Submission #57236
ソースコード
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 | #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 size_t N, K; vector< int > a; bool dfs( size_t idx, int now) { if (now == K) return true ; if (idx == N) return false ; bool ret = false ; ret |= dfs(idx + 1, now + a[idx]); ret |= dfs(idx + 1, now); return ret; } signed main() { ios_base::sync_with_stdio( false ); cin.tie(nullptr); cin >> N >> K; a.resize(N); for (auto &ai: a) cin >> ai; cout << (dfs(0, 0) ? "OK" : "NG" ) << "\n" ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0064 - 足し算できる? |
ユーザー名 | もけ |
投稿日時 | 2019-12-12 16:32:28 |
言語 | C++14 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1613 Byte |
最大実行時間 | 32 ms |
最大メモリ使用量 | 604 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
AddInput1.txt | AC | 22 ms | 604 KB |
1
|
AddInput2.txt | AC | 17 ms | 432 KB |
1
|
AddInput3.txt | AC | 23 ms | 388 KB |
1
|
AddInput4.txt | AC | 32 ms | 472 KB |
1
|
AddInput5.txt | AC | 20 ms | 556 KB |
1
|
AddInput6.txt | AC | 20 ms | 508 KB |
1
|