結果

問題 No.921 ずんだアロー
ユーザー Y17Y17
提出日時 2020-01-14 23:20:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 148,464 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-08-27 07:17:11
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 27 ms
4,636 KB
testcase_11 AC 28 ms
4,676 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 21 ms
4,380 KB
testcase_14 AC 24 ms
4,408 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 27 ms
4,376 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 28 ms
4,380 KB
testcase_22 AC 28 ms
4,380 KB
testcase_23 AC 29 ms
4,688 KB
testcase_24 AC 27 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+dp[0]-1);
        for(int i = 2;i < size;i++){
            dp[i] = max(dp[i-1]-1+pa[i].second, dp[i-2]+pa[i].second);
        }
    }

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

    return 0;
}
0