結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー t98slidert98slider
提出日時 2022-09-16 23:36:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 788 ms / 5,000 ms
コード長 1,034 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 169,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 17:02:55
合計ジャッジ時間 6,166 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 395 ms
4,376 KB
testcase_17 AC 248 ms
4,380 KB
testcase_18 AC 788 ms
4,380 KB
testcase_19 AC 232 ms
4,376 KB
testcase_20 AC 579 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 190 ms
4,376 KB
testcase_23 AC 81 ms
4,376 KB
testcase_24 AC 97 ms
4,376 KB
testcase_25 AC 110 ms
4,380 KB
testcase_26 AC 84 ms
4,376 KB
testcase_27 AC 111 ms
4,380 KB
testcase_28 AC 120 ms
4,376 KB
testcase_29 AC 176 ms
4,376 KB
testcase_30 AC 179 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    vector<int> p;
    for(int i = 0; i + 3 <= n; i++){
        if(s.substr(i, 3) != "con")continue;
        int cnt = 0;
        while(i + 3 <= n && s.substr(i, 3) == "con"){
            cnt++;
            i += 3;
        }
        p.push_back(cnt);
    }
    if(a == 1 && b == 1){
        cout << accumulate(p.begin(), p.end(), 0) << '\n';
        return 0;
    }
    vector<int> dp(6001, -(1 << 20));
    dp[0] = 0;
    for(int i = 0; i < p.size(); i++){
        for(int j = 6000 - p[i] / a; j >= 0; j--){
            if(dp[j] == -(1 << 30))continue;
            for(int k = p[i] / a; k >= 0; k--){
                dp[j + k] = max(dp[j + k], dp[j] + (p[i] - a * k) / b);
            }
        }
    }
    int ans = 0;
    for(int j = 6000; j >= 0; j--){
        if(dp[j] >= j - 1)ans = max(ans, j + min(j, dp[j]));
        ans = max(ans, 2 * min(j, dp[j]));
    }
    cout << ans << '\n';
}
0