結果

問題 No.1007 コイン集め
ユーザー amaridekinaiamaridekinai
提出日時 2020-03-06 22:41:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 165,204 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 09:50:27
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 48 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 47 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(void){
  int N,K; cin >> N >> K;
  K--;
  vector<int> A(N);
  vector<int> S(N,0);
  for(int i = 0; i < N; i++){ cin >> A[i];} 
  S[0] = A[0];
  
  for(int i = 1; i < N; i++){ 
    S[i] = S[i-1]+A[i];
  }
  
  if( A[K] == 0 ){ cout << 0 << endl; return 0;}
  
  // おそらくA[K] == 1がコーナーケース
  
  int left = K,right = K;
  if( A[K] == 1 ){ left--; right++;}
 
  
  while( left > 0 ){ 
    if(A[left] > 1 ){ left--; continue;}
    else{ 
      if( A[left] == 1 ){ //端点含める
        break;
      }
      else{ //A[left] == 0のとき、ここへは本来は来れない
 // が、ここを端点に含めたところで総数変わらないから別に入れてしまってもいい
        
        break;
      }
    }
  }//while-left
  
  while(right < N){ 
    if(A[right] > 1 ){ right++; continue;}
    else{ break;
        }
  }
  //left~rightまでの総和が欲しい 端点含む
  
  int ans = 0;
  
  if(A[K] == 1 ){ 
    
    int res1 = S[right];
    if(K){ res1 -= S[K-1];}
    int res2 = S[K];
    if(left){ res2 -= S[left-1];}
    
    ans = max(res1,res2);
    
  }
  
  else{
   ans = S[right];
   if(left){ ans -= S[left-1];
          }
  }
  
  cout << ans << endl;
  
  
  return 0;
}
0