結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,940 KB
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 AC 44 ms
6,940 KB
testcase_13 AC 43 ms
6,944 KB
testcase_14 AC 43 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:51:38: warning: 'mi[0]' may be used uninitialized [-Wmaybe-uninitialized]
   51 |   if(e[0]&&e[1])out(max(ans+mi[1],num+mi[0]));
      |                                   ~~~^~~~~~
main.cpp:12:26: note: in definition of macro 'out'
   12 | #define out(ans) cout << ans << endl
      |                          ^~~
main.cpp:28:6: note: 'mi[0]' was declared here
   28 |   ll mi[2];
      |      ^~
main.cpp:51:28: warning: 'mi[1]' may be used uninitialized [-Wmaybe-uninitialized]
   51 |   if(e[0]&&e[1])out(max(ans+mi[1],num+mi[0]));
      |                         ~~~^~~~~~
main.cpp:12:26: note: in definition of macro 'out'
   12 | #define out(ans) cout << ans << endl
      |                          ^~~
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,max((ll)0,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(e[0]&&e[1])out(max(ans+mi[1],num+mi[0]));
  else out(ans+num+a[k-1]);

  return 0;
}
0