結果

問題 No.921 ずんだアロー
ユーザー Kiona1018Kiona1018
提出日時 2019-11-08 22:02:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 168,492 KB
実行使用メモリ 8,968 KB
最終ジャッジ日時 2023-10-13 03:51:32
合計ジャッジ時間 3,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 33 ms
8,368 KB
testcase_11 AC 34 ms
8,848 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 25 ms
6,912 KB
testcase_14 AC 28 ms
7,724 KB
testcase_15 AC 18 ms
5,944 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 29 ms
7,840 KB
testcase_18 AC 36 ms
8,716 KB
testcase_19 AC 35 ms
8,728 KB
testcase_20 AC 36 ms
8,916 KB
testcase_21 AC 36 ms
8,968 KB
testcase_22 AC 36 ms
8,824 KB
testcase_23 AC 35 ms
8,696 KB
testcase_24 AC 36 ms
8,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> A(n+1);
    rep(i, 0, n) cin >> A[i+1];
    A[0] = A[1];

    vector<vector<int>> dp(n+1, vector<int> (2, 0));
    dp[0][0] = 0;
    dp[0][1] = 0;
    rep(i, 0, n)
    {
        dp[i+1][0] = max(dp[i][0], dp[i][1]);
        if (A[i] == A[i+1])
            dp[i+1][1] = max(dp[i][0], dp[i][1]) + 1;
        else
            dp[i+1][1] = dp[i][0] + 1;
    }
    cout << max(dp[n][0], dp[n][1]) << endl;
    return 0;
}
0