結果

問題 No.1007 コイン集め
ユーザー tnakao0123tnakao0123
提出日時 2020-03-07 01:23:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 1,500 ms
コード長 1,176 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 93,020 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 11:40:34
合計ジャッジ時間 1,755 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 17 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1007.cc:  No.1007 コイン集め - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll ass[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  k--;

  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    ass[i + 1] = ass[i] + as[i];
  }

  if (as[k] == 0)
    puts("0");
  else {
    int l, r;
    if (k > 0)
      for (l = k - 1; l > 0 && as[l] > 1; l--);
    else
      l = 0;
    if (k + 1 < n)
      for (r = k + 1; r + 1 < n && as[r] > 1; r++);
    else
      r = n - 1;
    //printf("l=%d, r=%d\n", l, r);

    if (as[k] == 1)
      printf("%lld\n", max(ass[k + 1] - ass[l], ass[r + 1] - ass[k]));
    else
      printf("%lld\n", ass[r + 1] - ass[l]);
  }
  return 0;
}
0