結果
問題 |
No.1007 コイン集め
|
ユーザー |
|
提出日時 | 2020-03-07 01:37:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 718 bytes |
コンパイル時間 | 1,403 ms |
コンパイル使用メモリ | 167,956 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 11:01:56 |
合計ジャッジ時間 | 2,310 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 1 |
ソースコード
#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; }