結果
問題 | No.1007 コイン集め |
ユーザー | konchanksu |
提出日時 | 2020-04-20 22:14:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 47 ms / 1,500 ms |
コード長 | 902 bytes |
コンパイル時間 | 682 ms |
コンパイル使用メモリ | 67,576 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-16 00:56:45 |
合計ジャッジ時間 | 1,879 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 43 ms
5,376 KB |
testcase_13 | AC | 43 ms
5,376 KB |
testcase_14 | AC | 43 ms
5,376 KB |
testcase_15 | AC | 17 ms
5,376 KB |
testcase_16 | AC | 17 ms
5,376 KB |
testcase_17 | AC | 17 ms
5,376 KB |
testcase_18 | AC | 46 ms
5,376 KB |
testcase_19 | AC | 47 ms
5,376 KB |
testcase_20 | AC | 46 ms
5,376 KB |
testcase_21 | AC | 47 ms
5,376 KB |
ソースコード
#include <iostream> #include <algorithm> using namespace std; long long n, k, i, j; int main(){ cin >> n >> k; long long p, q; long long a[n]; long long ans = 0; long long tmp = 0, tmpa = 0, tmpb = 0; for(i = 0; i < n; i++){cin >> a[i];} if(a[k - 1] == 0){ cout << 0 << endl; return 0; } p = 0, q = n - 1; for(i = 0; i < n; i++){ if(i < k - 1 && (a[i] == 1 || a[i] == 0)){ p = i; }else if(i > k - 1 && (a[i] == 1 || a[i] == 0)){ q = i; break; } } if(a[k - 1] == 1){ for(i = p; i <= q; i++){ if(i < k - 1) tmpa += a[i]; if(i > k - 1) tmpb += a[i]; } ans = max(tmpa, tmpb) + 1; }else{ for(i = p; i <= q; i++){ ans += a[i]; } } cout << ans << endl; return 0; }