Submission #65113
ソースコード
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 | #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,x,n) for(int i=(x);i<=(n);i++) #define rrep(i,n,x) for(int i=(n);i>=(x);i--) #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vb vector<bool> #define all(v) v.begin(),v.end() int main(){ cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n; cin>>n; vi a(n); rep(i,0,n-1) cin>>a[i]; vi ans; rep(bit,1,(1<<n)-1){ int sum=0; rep(i,0,n-1){ if (bit&(1<<i)) sum+=a[i]; } ans.push_back(sum); } sort(all(ans)); cout<<ans[0]<< "\n" ; rep(i,1,ans.size()-1){ if (ans[i]!=ans[i-1]) cout<<ans[i]<< "\n" ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1221 - bit全探索(基本) |
ユーザー名 | ei2005 |
投稿日時 | 2020-12-23 16:42:51 |
言語 | C++14 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 771 Byte |
最大実行時間 | 108 ms |
最大メモリ使用量 | 6212 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.text | AC | 44 ms | 476 KB |
1
|
in02.text | AC | 24 ms | 564 KB |
1
|
in03.text | AC | 56 ms | 648 KB |
1
|
in04.text | AC | 29 ms | 468 KB |
1
|
in05.text | AC | 28 ms | 792 KB |
1
|
in06.text | AC | 24 ms | 1000 KB |
1
|
in07.text | AC | 22 ms | 692 KB |
1
|
in08.text | AC | 96 ms | 5592 KB |
1
|
in09.text | AC | 107 ms | 5644 KB |
1
|
in10.text | AC | 108 ms | 6212 KB |
1
|