結果

問題 No.921 ずんだアロー
ユーザー Y17Y17
提出日時 2020-01-14 23:17:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 697 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 148,300 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-08-27 07:13:48
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 25 ms
4,684 KB
testcase_11 AC 26 ms
4,708 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 23 ms
4,392 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 23 ms
4,532 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 27 ms
4,628 KB
testcase_24 AC 25 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    vector<pair<int, int>> pa;
    pa.push_back({a[0], 1});
    int size = 1;

    for(int i = 1;i < n;i++){
        if(pa[size-1].first == a[i]){
            pa[size-1].second++;
        }else{
            pa.push_back({a[i], 1});
            size++;
        }
    }

    int dp[100010];
    dp[0] = pa[0].second;
    if(1 < size){
        dp[1] = max(dp[0], pa[1].second);
        for(int i = 2;i < size;i++){
            dp[i] = max(dp[i-1], dp[i-2]+pa[i].second);
        }
    }

    cout << dp[size-1] << endl;

    return 0;
}
0