結果
問題 | No.1007 コイン集め |
ユーザー | mgingin142857 |
提出日時 | 2020-03-06 22:14:11 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 47 ms / 1,500 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 1,656 ms |
コンパイル使用メモリ | 164,092 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-22 08:14:36 |
合計ジャッジ時間 | 2,858 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 43 ms
6,940 KB |
testcase_13 | AC | 43 ms
6,944 KB |
testcase_14 | AC | 43 ms
6,940 KB |
testcase_15 | AC | 18 ms
6,944 KB |
testcase_16 | AC | 18 ms
6,940 KB |
testcase_17 | AC | 17 ms
6,944 KB |
testcase_18 | AC | 47 ms
6,944 KB |
testcase_19 | AC | 47 ms
6,940 KB |
testcase_20 | AC | 46 ms
6,944 KB |
testcase_21 | AC | 46 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll,ll> P; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; const int inf=1e9+7; const ll INF=1LL<<61; const ll mod=1e9+7; 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; } int main(){ int i,j; ll n,k; cin>>n>>k; ll a[n+1]; ll ans=0; for(i=1;i<=n;i++) cin>>a[i]; if(a[k]==0){ cout<<0<<endl; return 0; } if(a[k]==1){ ll ans=0; ll cnt=0; for(i=k+1;i<=n;i++){ if(a[i]>=2) cnt+=a[i]; else { cnt+=a[i]; break; } } ans=max(ans,1+cnt); cnt=0; for(i=k-1;i>=1;i--){ if(a[i]>=2) cnt+=a[i]; else { cnt+=a[i]; break; } } ans=max(ans,1+cnt); cout<<ans<<endl; return 0; } else{ ll ans=0; ll cnt=0; for(i=k+1;i<=n;i++){ if(a[i]>=2) cnt+=a[i]; else { cnt+=a[i]; break; } } for(i=k-1;i>=1;i--){ if(a[i]>=2) cnt+=a[i]; else { cnt+=a[i]; break; } } ans=max(ans,a[k]+cnt); cout<<ans<<endl; return 0; } }