結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー AngrySadEightAngrySadEight
提出日時 2022-08-24 13:48:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,110 ms / 5,000 ms
コード長 1,443 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 74,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 16:52:47
合計ジャッジ時間 8,619 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 907 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 1,104 ms
4,380 KB
testcase_08 AC 743 ms
4,376 KB
testcase_09 AC 1,110 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 722 ms
4,376 KB
testcase_16 AC 222 ms
4,376 KB
testcase_17 AC 121 ms
4,376 KB
testcase_18 AC 835 ms
4,380 KB
testcase_19 AC 48 ms
4,380 KB
testcase_20 AC 810 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 53 ms
4,380 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 14 ms
4,376 KB
testcase_27 AC 36 ms
4,376 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 37 ms
4,376 KB
testcase_30 AC 25 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    
    vector<int> rle(0);
    int concnt = 0;
    int now_idx = 0;
    while(true){
        if (now_idx >= N - 2){
            if (concnt >= 1){
                rle.push_back(concnt);
            }
            break;
        }
        else if (S.substr(now_idx, 3) == "con"){
            now_idx += 3;
            concnt++;
        }
        else{
            now_idx++;
            if (concnt >= 1){
                rle.push_back(concnt);
            }
            concnt = 0;
        }
    }
    int INF = 50000;
    int len = rle.size();
    vector<int> dp1(8338, INF * -1);
    vector<int> dp2(8338, INF * -1);
    dp1[0] = 0;
    int times = 0;
    for (int i = 0; i < len; i++){
        times += rle[i] / A;
        for (int j = 0; j <= times; j++){
            for (int k = 0; k <= (rle[i] / A); k++){
                if (j + k >= 8338) continue;
                dp2[j + k] = max(dp2[j + k], dp1[j] + (rle[i] - A * k) / B);
            }
        }
        for (int j = 0; j < 8338; j++){
            dp1[j] = dp2[j];
            dp2[j] = INF * -1;
        }
    }
    int ans = 0;
    for (int j = 0; j < 8338; j++){
        if (dp1[j] >= j - 1) ans = max(ans, 2 * j - 1);
        if (dp1[j] >= j) ans = max(ans, 2 * j);
    }
    cout << ans << endl;
}
0