Submission #00030
ソースコード
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 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include "bits/stdc++.h" // Begin {{{ using namespace std; #define all(x) x.begin(), x.end() #define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i) #define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i) #define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i) #define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__) using i64 = int_fast64_t; using pii = pair<i64, i64>; template < class T> using MaxHeap = priority_queue<T>; template < class T> using MinHeap = priority_queue<T, vector<T>, greater<>>; 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 ); } inline i64 sigma(i64 n) { return n * (1 + n) >> 1; } inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; } constexpr int INF = 0x3f3f3f3f; constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int MOD = int (1e9) + 7; #ifndef DEBUG #define dump(...) #endif inline void input() {} template < class Head, class ... Tail> inline void input(Head&& head, Tail&&... tail) { cin >> head; input(forward<Tail>(tail)...); } inline void outs() { cout << "\n" ; } template < class Head, class ... Tail> inline void outs(Head&& head, Tail&&... tail) { cout << head << ( sizeof ...(tail) ? " " : "" ); outs(forward<Tail>(tail)...); } template < class T> inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n" [&e == &vec.back()]; } template < class T> inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); } inline void outl() { cout << "\n" ; } template < class Head, class ... Tail> inline void outl(Head&& head, Tail&&... tail) { cout << head << ( sizeof ...(tail) ? "\n" : "" ); outl(forward<Tail>(tail)...); } template < class T> inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n" ; } inline void outn() {} template < class Head, class ... Tail> inline void outn(Head&& head, Tail&&... tail) { cout << head; outn(forward<Tail>(tail)...); } template < class T> inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; } 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...)); } // }}} End signed main() { ios_base::sync_with_stdio( false ); cin.tie(nullptr); size_t N; cin >> N; vector<intmax_t> a(N); for ( size_t i = 0; i < N; ++i) { cin >> a[i]; } intmax_t res = 0; for ( size_t bit = 0; bit < (1 << (N - 2)); ++bit) { intmax_t sum = a[0]; bool endloop = false ; for ( size_t i = 0; i < N - 2; ++i) { if (bit & 1 << i) { sum += a[i + 1]; } else { sum -= a[i + 1]; } if (sum < 0 || sum > 20) { endloop = true ; break ; } } if (!endloop && sum == a[N - 1]) { res++; } } cout << res << "\n" ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0002 - 1年生 (A First Grader) |
ユーザー名 | もけ |
投稿日時 | 2019-10-30 17:22:28 |
言語 | C++14 |
状態 | Wrong Answer |
得点 | 20 |
ソースコード長 | 3353 Byte |
最大実行時間 | 79 ms |
最大メモリ使用量 | 644 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | 入力1 | 20 / 20 | *1.txt |
2 | 入力2 | 0 / 20 | *2.txt |
3 | 入力3 | 0 / 20 | *3.txt |
4 | 入力4 | 0 / 20 | *4.txt |
5 | 入力5 | 0 / 20 | *5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
2011-yo-t4-in1.txt | AC | 24 ms | 604 KB |
1
|
||||
2011-yo-t4-in2.txt | WA | 29 ms | 560 KB |
2
|
||||
2011-yo-t4-in3.txt | WA | 22 ms | 644 KB |
3
|
||||
2011-yo-t4-in4.txt | WA | 79 ms | 600 KB |
4
|
||||
2011-yo-t4-in5.txt | WA | 20 ms | 556 KB |
5
|