Submission #57204
ソースコード
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 | #include "bits/stdc++.h" #pragma GCC optimize("Ofast") // Begin {{{ using namespace std; #ifndef DEBUG #define dump(...) #endif 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 T> inline vector<T> make_v( const T &initvalue, size_t sz) { return vector<T>(sz, initvalue); } template < class T, class ... Args> inline auto make_v( const T &initvalue, size_t sz, Args... args) { return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...)); } constexpr int INF = 0x3f3f3f3f; constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL; using pii = pair<int64_t, int64_t>; template < class T> using MaxHeap = priority_queue<T>; template < class T> using MinHeap = priority_queue<T, vector<T>, greater<>>; constexpr int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; inline bool inside( int y, int x, int H, int W) { return (y >= 0 && x >= 0 && y < H && x < W); } // }}} End signed main() { ios_base::sync_with_stdio( false ); cin.tie(nullptr); size_t N; cin >> N; vector< int > a(N); for (auto &ai: a) cin >> ai; vector< int > res; for ( size_t bit = 0; bit < (1 << N); ++bit) { int sum = 0; for ( size_t i = 0; i < N; ++i) { if (bit & (1 << i)) { sum += a[i]; } } res.emplace_back(sum); } sort(res.begin(), res.end()); res.erase(unique(res.begin(), res.end()), res.end()); for ( size_t i = 1; i < res.size(); ++i) { cout << res[i] << "\n" ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1221 - bit全探索(基本) |
ユーザー名 | r1910 |
投稿日時 | 2019-12-11 17:53:57 |
言語 | C++14 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 1783 Byte |
最大実行時間 | 107 ms |
最大メモリ使用量 | 6708 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.text | AC | 26 ms | 604 KB |
1
|
in02.text | AC | 27 ms | 432 KB |
1
|
in03.text | AC | 19 ms | 520 KB |
1
|
in04.text | AC | 23 ms | 592 KB |
1
|
in05.text | AC | 23 ms | 660 KB |
1
|
in06.text | AC | 17 ms | 740 KB |
1
|
in07.text | AC | 20 ms | 684 KB |
1
|
in08.text | AC | 95 ms | 6216 KB |
1
|
in09.text | AC | 107 ms | 5500 KB |
1
|
in10.text | AC | 100 ms | 6708 KB |
1
|