結果

問題 No.1007 コイン集め
ユーザー pekempeypekempey
提出日時 2020-03-06 22:21:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 165,164 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 08:41:31
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 43 ms
6,944 KB
testcase_13 AC 44 ms
6,944 KB
testcase_14 AC 44 ms
6,944 KB
testcase_15 WA -
testcase_16 AC 17 ms
6,944 KB
testcase_17 WA -
testcase_18 AC 47 ms
6,944 KB
testcase_19 AC 46 ms
6,940 KB
testcase_20 AC 47 ms
6,940 KB
testcase_21 AC 47 ms
6,940 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 && A[l - 1] >= 1) l--;
  while (r <= N - 2 && A[r] >= 2 && A[r + 1] >= 1) 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] <= 2) {
    cout << max(sl, sr) + A[K] << endl;
  } else {
    cout << sl + sr + A[K] << endl;
  }
}
0