結果
問題 | No.1007 コイン集め |
ユーザー |
![]() |
提出日時 | 2020-03-06 21:49:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 1,500 ms |
コード長 | 769 bytes |
コンパイル時間 | 2,512 ms |
コンパイル使用メモリ | 193,268 KB |
最終ジャッジ日時 | 2025-01-09 05:00:47 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,k; cin>>n>>k; k--; vector<Int> as(n); for(Int i=0;i<n;i++) cin>>as[i]; if(as[k]==0) drop(0); Int l=0,r=0; for(Int i=k-1;i>=0;i--){ if(as[i]==0) break; l+=as[i]; if(as[i]==1) break; } for(Int i=k+1;i<n;i++){ if(as[i]==0) break; r+=as[i]; if(as[i]==1) break; } if(as[k]==1) cout<<max(l,r)+1<<endl; else cout<<l+r+as[k]<<endl; return 0; }