結果
| 問題 | No.1007 コイン集め |
| コンテスト | |
| ユーザー |
yuboolku
|
| 提出日時 | 2020-03-06 23:08:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,171 bytes |
| 記録 | |
| コンパイル時間 | 1,373 ms |
| コンパイル使用メモリ | 167,752 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-10-14 09:37:29 |
| 合計ジャッジ時間 | 2,744 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 1 |
ソースコード
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
int main(){
int N, K;
cin >> N >> K;
int l = 0;
int r = N-1;
ll A[N];
rep(i, N) {
cin >> A[i];
if (A[i] == 1 && i < K - 1) {
l = i;
} else if (A[i] == 1 && i > K - 1 && r == N-1) {
r = i;
}
}
ll ans1 = 0;
ll ans2 = 0;
REP(i, l, K) {
ans1 += A[i];
}
REP(i, K, r+1) {
ans2 += A[i];
}
// cout << ans1 << " " << ans2 << endl;
if (A[K - 1] == 0) {
cout << 0 << endl;
} else if (A[K - 1] == 1) {
cout << max(ans1 , ans2+1) << endl;
} else {
cout << ans1 + ans2 << endl;
}
}
yuboolku