結果

問題 No.921 ずんだアロー
ユーザー YamaKasaYamaKasa
提出日時 2019-12-04 02:49:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 168,436 KB
実行使用メモリ 4,832 KB
最終ジャッジ日時 2023-08-19 02:25:03
合計ジャッジ時間 3,121 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 27 ms
4,804 KB
testcase_11 AC 28 ms
4,832 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 21 ms
4,468 KB
testcase_14 AC 25 ms
4,496 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 29 ms
4,780 KB
testcase_24 AC 28 ms
4,380 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], max(dp[l - 1], dp[l - 2])) << "\n";
    // for (auto i : b) {
    //     cout << i.first << " " << i.second << "\n";
    // }
    return 0;
}
0