Submission #59365


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma GCC optimize("Ofast")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
int n;
vector<int> a, res;
void dfs(vector<int>& vec){
if(vec.size() == n){
int sum = 0;
for(int i = 0; i < n; ++i){
if(vec[i] == 1){
sum += a[i];
}
}
res.emplace_back(sum);
return;
}
for(int i = 0; i <= 1; ++i){
vec.emplace_back(i);
dfs(vec);
vec.pop_back();
}
}
signed main(void){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> n;
a.resize(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
vector<int> vec;
dfs(vec);
sort(all(res));
res.erase(unique(all(res)), res.end());
for(auto&& e : res){
if(e) cout << e << '\n';
}
return 0;
}

ステータス

項目 データ
問題 1221 - bit全探索(基本)
ユーザー名 ei1903
投稿日時 2020-05-10 21:54:28
言語 C++17
状態 Accepted
得点 1
ソースコード長 2431 Byte
最大実行時間 105 ms
最大メモリ使用量 10616 KB

セット

セット 得点 Cases
1 ALL 1 / 1 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.text AC 40 ms 604 KB
1
in02.text AC 27 ms 428 KB
1
in03.text AC 29 ms 508 KB
1
in04.text AC 22 ms 576 KB
1
in05.text AC 30 ms 756 KB
1
in06.text AC 22 ms 840 KB
1
in07.text AC 24 ms 660 KB
1
in08.text AC 105 ms 9492 KB
1
in09.text AC 98 ms 9028 KB
1
in10.text AC 105 ms 10616 KB
1