結果

問題 No.921 ずんだアロー
ユーザー rogi52rogi52
提出日時 2022-10-01 04:34:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 738 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 205,264 KB
実行使用メモリ 5,044 KB
最終ジャッジ日時 2023-08-24 21:55:05
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 12 ms
5,020 KB
testcase_11 AC 12 ms
5,044 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 10 ms
4,520 KB
testcase_14 AC 10 ms
4,792 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 11 ms
4,568 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 13 ms
4,996 KB
testcase_24 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    vector<pair<int,int>> v = {{A[0], 1}};
    for(int i = 1; i < N; i++) {
        if(v.back().first == A[i]) v.back().second++;
        else v.push_back({A[i], 1});
    }

    A.clear();
    for(auto [x, c] : v) A.push_back(c);
    N = int(A.size());
    int dp[N + 1][2] = {};
    for(int i = 0; i < N; i++) {
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + A[i]);
        dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][0], dp[i][1]));
    }
    cout << max(dp[N][0], dp[N][1]) << "\n";
}
0