結果

問題 No.1007 コイン集め
ユーザー StrorkisStrorkis
提出日時 2020-03-06 22:50:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 69,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 10:03:02
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 8 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 16 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K; cin >> N >> K; K--;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int left = 0;
  for (int i = K-1; i >= 0; i--) {
    if (A[i] >= 2) left += A[i];
    else {
      left += A[i];
      break;
    }
  }

  int right = 0;
  for (int i = K+1; i < N; i++) {
    if (A[i] >= 2) right += A[i];
    else {
      left += A[i];
      break;
    }
  }

  int ans;
  if (A[K] == 0) ans = 0;
  else if (A[K] == 1) ans = A[K] + max(left, right);
  else ans = A[K] + left + right;
  cout << ans << "\n";
}
0