結果
問題 |
No.1007 コイン集め
|
ユーザー |
|
提出日時 | 2020-03-07 01:39:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 1,500 ms |
コード長 | 718 bytes |
コンパイル時間 | 1,681 ms |
コンパイル使用メモリ | 169,468 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 11:02:41 |
合計ジャッジ時間 | 2,656 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, K; cin >> n >> K; --K; vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } if (a[K] == 0) { cout << 0 << "\n"; return 0; } ll cnt_r = 1; for (int i = K + 1; i < n; ++i) { cnt_r += a[i]; if (a[i] <= 1) break; } ll cnt_l = 1; for (int i = K - 1; i >= 0; --i) { cnt_l += a[i]; if (a[i] <= 1) break; } if (a[K] == 1) { cout << max(cnt_l, cnt_r) << "\n"; } else { cout << cnt_l + cnt_r + a[K] - 2 << "\n"; } return 0; }