結果
| 問題 | No.1007 コイン集め |
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-07 17:46:34 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 1,500 ms |
| コード長 | 680 bytes |
| 記録 | |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 183,108 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-02 21:21:33 |
| 合計ジャッジ時間 | 2,110 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:67,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:1:
In member function 'constexpr __gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+(difference_type) const [with _Iterator = int*; _Container = std::vector<int>]',
inlined from 'int main()' at main.cpp:25:57:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_iterator.h:1148:47: warning: 'r' may be used uninitialized [-Wmaybe-uninitialized]
1148 | { return __normal_iterator(_M_current + __n); }
| ^~~
main.cpp: In function 'int main()':
main.cpp:11:11: note: 'r' was declared here
11 | int l,r;
| ^
In member function 'constexpr __gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+(difference_type) const [with _Iterator = int*; _Container = std::vector<int>]',
inlined from 'int main()' at main.cpp:24:32:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_iterator.h:1148:47: warning: 'l' may be used uninitialized [-Wmaybe-uninitialized]
1148 | { return __normal_iterator(_M_current + __n); }
| ^~~
main.cpp: In function 'int main()':
main.cpp:11:9: note: 'l' was declared here
11 | int l,r;
| ^
ソースコード
#include<bits/stdc++.h>
int main(){
int n,k;std::cin>>n>>k;k--;
std::vector<int>a(n);
for(int&x:a)std::cin>>x;
long long K=a.at(k);
if(K==0){
std::cout<<0<<std::endl;
return 0;
}
int l,r;
for(int i=k+1;i<=n;i++){
if(i==n||a.at(i)<2){
r=i-(i==n||a.at(i)==0);
break;
}
}
for(int i=k-1;i>=-1;i--){
if(i==-1||a.at(i)<2){
l=i+(i==-1||a.at(i)==0);
break;
}
}
long long L=std::accumulate(a.begin()+l,a.begin()+k,0ll);
long long R=std::accumulate(a.begin()+k+1,a.begin()+r+1,0ll);
std::cout<<(K==1?std::max(L,R)+K:L+K+R)<<std::endl;
}
ngtkana