結果

問題 No.921 ずんだアロー
ユーザー YamaKasaYamaKasa
提出日時 2019-12-04 02:26:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 169,412 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-08-19 01:44:25
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 24 ms
4,620 KB
testcase_11 AC 25 ms
4,804 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 18 ms
4,480 KB
testcase_14 AC 20 ms
4,384 KB
testcase_15 AC 12 ms
4,384 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 24 ms
4,652 KB
testcase_24 AC 24 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<pair<int, int>> b;
    b.push_back(make_pair(A[0], 1));
    for (int i = 1; i < N; i++) {
        if (A[i] == (b.back()).first) {
            (b.back()).second++;
        } else {
            b.push_back(make_pair(A[i], 1));
        }
    }
    int l = b.size();
    int dp[l + 1]{};
    dp[1] = b[0].second;
    if (l == 1) {
        cout << dp[1] << "\n";
        return 0;
    }
    dp[2] = b[1].second;
    for (int i = 2; i < l; i++) {
        dp[i + 1] = max(dp[i - 2], dp[i - 1]) + b[i].second;
    }
    cout << max(dp[l], dp[l - 1]) << "\n";

    return 0;
}
0