結果

問題 No.1007 コイン集め
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-03-06 22:58:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 1,500 ms
コード長 1,391 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 76,556 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-04 12:35:19
合計ジャッジ時間 1,799 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  ll n, k; cin >> n >> k;
  vector<ll> a(n); rep(i, n) cin >> a[i];

  if (a[k - 1] == 0) {
    outl(0)
    return 0;
  }

  ll lsum = 0, rsum = 0;
  for (int i = k - 2; i >= 0; i--) {
    lsum += a[i];
    if (a[i] <= 1) break;
  }
  for (int i = k; i < n; i++) {
    rsum += a[i];
    if (a[i] <= 1) break;
  }

  if (a[k - 1] == 1) {
    outl(max(lsum, rsum) + 1)
  } else {
    outl(lsum + rsum + a[k - 1])
  }
}
0