結果

問題 No.1007 コイン集め
ユーザー amaridekinaiamaridekinai
提出日時 2020-03-06 22:31:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 165,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 08:56:36
合計ジャッジ時間 3,141 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,248 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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 47 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;}
  
  int left = K,right = K;
  
  //leftはどれだけ左に行けるか
  
  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 = S[right];
  if(left){ ans -= S[left-1];
          }
  
  cout << ans << endl;
  
  return 0;
}
0