提出 #13927176
ソースコード 拡げる
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, A[101010];
//---------------------------------------------------------------------------------------------------
ll solve() {
if (N == 0) {
if (A[0] == 1) return 1;
else return -1;
}
if (A[0] != 0) return -1;
ll tot = 0;
rep(i, 0, N + 1) tot += A[i];
ll cur = 1;
ll ans = 1;
rep(i, 1, N + 1) {
cur *= 2;
if (cur < A[i]) return -1;
ans += min(cur, tot);
cur = min(cur, tot) - A[i];
tot -= A[i];
}
return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, N + 1) cin >> A[i];
cout << solve() << endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Folia |
| ユーザ | hamayanhamayan |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 600 |
| コード長 | 1952 Byte |
| 結果 | AC |
| 実行時間 | 17 ms |
| メモリ | 4020 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt, s4.txt, s5.txt |
| All | 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, s1.txt, s2.txt, s3.txt, s4.txt, s5.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0.txt | AC | 12 ms | 3744 KiB |
| 1.txt | AC | 7 ms | 3688 KiB |
| 10.txt | AC | 4 ms | 3676 KiB |
| 11.txt | AC | 10 ms | 3840 KiB |
| 12.txt | AC | 4 ms | 3696 KiB |
| 13.txt | AC | 6 ms | 3720 KiB |
| 14.txt | AC | 11 ms | 3968 KiB |
| 15.txt | AC | 15 ms | 3840 KiB |
| 16.txt | AC | 16 ms | 3920 KiB |
| 17.txt | AC | 16 ms | 3968 KiB |
| 18.txt | AC | 14 ms | 3888 KiB |
| 19.txt | AC | 16 ms | 3976 KiB |
| 2.txt | AC | 5 ms | 3620 KiB |
| 20.txt | AC | 15 ms | 3900 KiB |
| 21.txt | AC | 16 ms | 3840 KiB |
| 22.txt | AC | 15 ms | 3972 KiB |
| 23.txt | AC | 11 ms | 3808 KiB |
| 24.txt | AC | 13 ms | 3928 KiB |
| 25.txt | AC | 10 ms | 3628 KiB |
| 26.txt | AC | 3 ms | 3616 KiB |
| 27.txt | AC | 9 ms | 3612 KiB |
| 28.txt | AC | 17 ms | 4020 KiB |
| 29.txt | AC | 14 ms | 3936 KiB |
| 3.txt | AC | 2 ms | 3592 KiB |
| 30.txt | AC | 2 ms | 3516 KiB |
| 31.txt | AC | 2 ms | 3508 KiB |
| 32.txt | AC | 2 ms | 3508 KiB |
| 33.txt | AC | 2 ms | 3636 KiB |
| 34.txt | AC | 3 ms | 3560 KiB |
| 35.txt | AC | 6 ms | 3624 KiB |
| 4.txt | AC | 4 ms | 3604 KiB |
| 5.txt | AC | 7 ms | 3708 KiB |
| 6.txt | AC | 8 ms | 3724 KiB |
| 7.txt | AC | 15 ms | 3896 KiB |
| 8.txt | AC | 3 ms | 3548 KiB |
| 9.txt | AC | 10 ms | 3760 KiB |
| s1.txt | AC | 2 ms | 3636 KiB |
| s2.txt | AC | 2 ms | 3504 KiB |
| s3.txt | AC | 2 ms | 3504 KiB |
| s4.txt | AC | 2 ms | 3496 KiB |
| s5.txt | AC | 6 ms | 3500 KiB |