結果

問題 No.1765 While Shining
ユーザー ytftytft
提出日時 2021-12-27 00:08:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 167,640 KB
実行使用メモリ 5,224 KB
最終ジャッジ日時 2023-10-24 19:43:47
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 22 ms
4,648 KB
testcase_10 AC 32 ms
5,116 KB
testcase_11 AC 29 ms
4,936 KB
testcase_12 AC 30 ms
5,044 KB
testcase_13 AC 27 ms
4,908 KB
testcase_14 AC 33 ms
5,224 KB
testcase_15 AC 34 ms
5,224 KB
testcase_16 AC 35 ms
5,224 KB
testcase_17 AC 34 ms
5,224 KB
testcase_18 AC 34 ms
5,224 KB
testcase_19 AC 33 ms
5,224 KB
testcase_20 AC 34 ms
5,224 KB
testcase_21 AC 35 ms
5,224 KB
testcase_22 AC 34 ms
5,224 KB
testcase_23 AC 34 ms
5,224 KB
testcase_24 AC 35 ms
5,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:18:9: warning: 'count' may be used uninitialized [-Wmaybe-uninitialized]
   18 |         ++count;
      |         ^~~~~~~
main.cpp:4:11: note: 'count' was declared here
    4 |     int N,count;
      |           ^~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,count;
    long long ans=0;
    cin>>N;
    if(N==1){
    	cout<<0<<endl;
    	return 0;
    }
    int A[N],B[N];
    for(int i=0;i<N;++i){
        cin>>A[i];
        A[i]^=i%2;
    }
    A[N-1]=!A[N-2];
    for(int i=N-2;i>=0;--i){
        ++count;
        if(A[i]!=A[i+1]){
            count=1;
        }
        B[i]=count;
    }
    for(int i=0;i<N-1;++i){
        if(A[i]^(i%2)){
            ans+=B[i];
        }
    }
    cout<<ans<<endl;
}
0