結果

問題 No.1007 コイン集め
ユーザー pekempeypekempey
提出日時 2020-03-06 22:28:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 1,500 ms
コード長 802 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 166,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 08:52:05
合計ジャッジ時間 2,684 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 AC 39 ms
5,376 KB
testcase_14 AC 39 ms
5,376 KB
testcase_15 AC 16 ms
5,376 KB
testcase_16 AC 18 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 43 ms
5,376 KB
testcase_19 AC 41 ms
5,376 KB
testcase_20 AC 42 ms
5,376 KB
testcase_21 AC 43 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  int N, K; cin >> N >> K; K--;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  int l = K - 1;
  int r = K + 1;
  while (l >= 1 && A[l] >= 2) l--;
  while (r <= N - 2 && A[r] >= 2) r++;
  if (l >= 0 && A[l] == 0) l++;
  if (r <= N - 1 && A[r] == 0) r--;
  ll sl = 0;
  for (int i = max(0, l); i <= K - 1; i++) {
    sl += A[i];
  }
  ll sr = 0;
  for (int i = K + 1; i <= min(N - 1, r); i++) {
    sr += A[i];
  }
  if (A[K] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (A[K] <= 1) {
    cout << max(sl, sr) + A[K] << endl;
  } else {
    cout << sl + sr + A[K] << endl;
  }
}
0