結果
問題 | No.1007 コイン集め |
ユーザー | ngtkana |
提出日時 | 2020-03-07 17:46:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 46 ms / 1,500 ms |
コード長 | 680 bytes |
コンパイル時間 | 1,663 ms |
コンパイル使用メモリ | 168,908 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 04:20:51 |
合計ジャッジ時間 | 3,374 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 42 ms
5,248 KB |
testcase_13 | AC | 42 ms
5,248 KB |
testcase_14 | AC | 42 ms
5,248 KB |
testcase_15 | AC | 17 ms
5,248 KB |
testcase_16 | AC | 18 ms
5,248 KB |
testcase_17 | AC | 18 ms
5,248 KB |
testcase_18 | AC | 45 ms
5,248 KB |
testcase_19 | AC | 46 ms
5,248 KB |
testcase_20 | AC | 46 ms
5,248 KB |
testcase_21 | AC | 45 ms
5,248 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:47, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function '__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@12/12.3.0/include/c++/12/bits/stl_iterator.h:1144:47: warning: 'l' may be used uninitialized [-Wmaybe-uninitialized] 1144 | { 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; | ^ In member function '__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@12/12.3.0/include/c++/12/bits/stl_iterator.h:1144:47: warning: 'r' may be used uninitializ
ソースコード
#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; }