結果
問題 |
No.1007 コイン集め
|
ユーザー |
|
提出日時 | 2020-03-06 21:44:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 500 bytes |
コンパイル時間 | 1,854 ms |
コンパイル使用メモリ | 192,444 KB |
最終ジャッジ日時 | 2025-01-09 04:57:10 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 17 RE * 2 |
コンパイルメッセージ
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"); 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; }