結果

問題 No.1765 While Shining
ユーザー monnumonnu
提出日時 2021-11-26 22:32:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 226,084 KB
実行使用メモリ 5,736 KB
最終ジャッジ日時 2023-09-12 05:11:09
合計ジャッジ時間 5,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 21 ms
4,736 KB
testcase_10 AC 31 ms
5,280 KB
testcase_11 AC 27 ms
4,936 KB
testcase_12 AC 30 ms
5,284 KB
testcase_13 AC 26 ms
4,868 KB
testcase_14 AC 33 ms
5,432 KB
testcase_15 AC 32 ms
5,708 KB
testcase_16 AC 33 ms
5,496 KB
testcase_17 AC 33 ms
5,388 KB
testcase_18 AC 33 ms
5,396 KB
testcase_19 AC 32 ms
5,464 KB
testcase_20 AC 33 ms
5,496 KB
testcase_21 AC 33 ms
5,496 KB
testcase_22 AC 32 ms
5,384 KB
testcase_23 AC 32 ms
5,736 KB
testcase_24 AC 32 ms
5,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000
#define MOD 998244353
#define MAX 1000000

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  vector<int> sum0(N,0),sum1(N,0);
  sum0[N-1]=0;
  sum1[N-1]=0;
  ll ans=0;
  for(int i=N-2;i>=0;i--){
    if(A[i]==1){
      sum1[i]=sum0[i+1]+1;
      ans+=(ll)sum1[i];
    }else{
      sum0[i]=sum1[i+1]+1;
    }
  }
  cout<<ans<<'\n';
}
0