結果
問題 | No.1007 コイン集め |
ユーザー |
|
提出日時 | 2020-03-06 21:45:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 1,500 ms |
コード長 | 502 bytes |
コンパイル時間 | 5,115 ms |
コンパイル使用メモリ | 191,664 KB |
最終ジャッジ日時 | 2025-01-09 04:58:11 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n,k; scanf("%d%d",&n,&k); k--; | ~~~~~^~~~~~~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n,k; scanf("%d%d",&n,&k); k--; vector<int> a(n); rep(i,n) scanf("%d",&a[i]); if(a[k]==0) return puts("0"),0; lint lsum=0,rsum=0; for(int i=k-1;i>=0;i--){ lsum+=a[i]; if(a[i]<=1) break; } for(int i=k+1;i<n;i++){ rsum+=a[i]; if(a[i]<=1) break; } if(a[k]==1) printf("%lld\n",a[k]+max(lsum,rsum)); else printf("%lld\n",a[k]+lsum+rsum); return 0; }