結果

問題 No.1007 コイン集め
ユーザー ngtkanangtkana
提出日時 2020-03-07 17:46:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 1,500 ms
コード長 680 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 166,972 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 04:43:26
合計ジャッジ時間 2,954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 44 ms
6,944 KB
testcase_13 AC 44 ms
6,940 KB
testcase_14 AC 43 ms
6,944 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 18 ms
6,940 KB
testcase_17 AC 17 ms
6,944 KB
testcase_18 AC 48 ms
6,940 KB
testcase_19 AC 47 ms
6,940 KB
testcase_20 AC 47 ms
6,944 KB
testcase_21 AC 48 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_algobase.h:67,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/algorithm:60,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:51,
                 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:25:57:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/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 '__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/13.2.0/include/c++/13/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;
      |         ^

ソースコード

diff #

#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;
}

0