結果

問題 No.921 ずんだアロー
ユーザー YamaKasaYamaKasa
提出日時 2019-12-04 02:42:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 167,596 KB
実行使用メモリ 4,852 KB
最終ジャッジ日時 2023-08-19 02:18:31
合計ジャッジ時間 2,935 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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