結果

問題 No.921 ずんだアロー
ユーザー kyoprounokyoprouno
提出日時 2019-11-08 23:05:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 901 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 168,920 KB
実行使用メモリ 5,520 KB
最終ジャッジ日時 2023-10-13 04:42:15
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 27 ms
5,432 KB
testcase_11 AC 29 ms
5,320 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 20 ms
4,732 KB
testcase_14 AC 23 ms
4,700 KB
testcase_15 AC 15 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 24 ms
4,960 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 29 ms
5,520 KB
testcase_24 AC 28 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b;
    int m=1;
    int size=1;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    a.push_back(-1);
    for(int i=1;i<n+1;i++){
        if(a[i]==a[i-1]){
            m++;
        }
        else{
            b.push_back(m);
            size++;
            m=1;
        }
    }
    //dp[i-1][0]はi番目の数字を選ばなかったときの最大値
    int dp[size+1][3];
    for(int i=0;i<size;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=-1;
        }
    }
    dp[0][0]=0;
    dp[0][1]=b[0];
    for(int i=1;i<size;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][1]=dp[i-1][0]+b[i];
    }
    int ans=0;
    for(int i=0;i<size;i++){
        for(int j=0;j<2;j++){
            ans=max(ans,dp[i][j]);
        }
    }
    cout <<  ans << endl;
}
0