結果

問題 No.921 ずんだアロー
ユーザー mikianaaamikianaaa
提出日時 2020-09-09 12:58:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 166,528 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 11:33:24
合計ジャッジ時間 3,347 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> A(N), dp(N + 5, 0);
    rep(i, N) { cin >> A[i]; }

    dp[0] = 1;
    rep(i, N) {
        if (i > 0 && A[i] == A[i - 1])
            chmax(dp[i], dp[i - 1] + 1);
        if (i > 0)
            chmax(dp[i], dp[i - 1]);
        if (i > 1)
            chmax(dp[i], dp[i - 2] + 1);
    }

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

    return 0;
}
0