結果

問題 No.1007 コイン集め
ユーザー shoshoshoshoshosho
提出日時 2020-03-06 23:34:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,246 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 164,760 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 10:40:08
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/istream:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/sstream:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:127,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:50:3:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ostream:204:25: warning: 'mi[0]' may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:28:6: note: 'mi[0]' was declared here
   28 |   ll mi[2];
      |      ^~
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:50:3:
/home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/ostream:204:25: warning: 'mi[1]' may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:28:6: note: 'mi[1]' was declared here
   28 |   ll mi[2];
      |      ^~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,k;cin>>n>>k;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll ans=0;
  bool e[2];
  e[0]=false;
  ll mi[2];
  repr(i,k-2,0){
    if(a[i]<=1){
      if(!e[0])mi[0]=ans+a[i];
      e[0]=true;
    }
    if(a[i]==0)break;
    ans+=a[i];
  }

  e[1]=false;
  ll num=0;
  rep(i,k,n){
    if(a[i]<=1){
      if(!e[1])mi[1]=num+a[i];
      e[1]=true;
    }
    if(a[i]==0)break;
    num+=a[i];
  }

  out(ans<<" "<<num);
  out(mi[0]<<" "<<mi[1]);
  if(a[k-1]==0)out(0);
  else if(a[k-1]==1)out(a[k-1]+max(mi[0],mi[0]));
  else if(e[0]&&e[1])out(mi[0]+a[k-1]+mi[1]);
  else out(ans+num+a[k-1]);

  return 0;
}
0