提出 #64943874


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
template <typename T> void chmax(T &a, T b) {if (a < b) a = b;}
int main() {
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int ocount = 0;
    for (int i=0; i<n; i++) if (s[i] == 'o') ocount++;
    if (ocount == k) {
        for (int i=0; i<n; i++) if (s[i] == '?') s[i] = '.';
        cout << s << "\n";
        return 0;
    }

    auto calc_dp = [&] (string s) {
        vector dp(n+1, vector<int>(2, -INF));
        dp[0] = {0, 0};
        for (int i=0; i<n; i++) {
            if (s[i] != 'o') chmax(dp[i+1][0], max(dp[i][0], dp[i][1]));
            if (s[i] != '.') chmax(dp[i+1][1], dp[i][0] + 1);
        }
        return dp;
    };
    auto dpl = calc_dp(s);
    reverse(s.begin(), s.end());
    auto dpr = calc_dp(s);
    reverse(dpr.begin(), dpr.end());
    reverse(s.begin(), s.end());

    for (int i=0; i<n; i++) {
        if (s[i] != '?') continue;
        if (max(dpl[i][0], dpl[i][1]) + max(dpr[i+1][0], dpr[i+1][1]) < k) s[i] = 'o';
        else if (dpl[i][0] +dpr[i+1][0] + 1 < k) s[i] = '.';
    }
    cout << s << '\n';
}

提出情報

提出日時
問題 D - Logical Filling
ユーザ seekworser
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1163 Byte
結果 AC
実行時間 24 ms
メモリ 25588 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3484 KiB
00_sample_01.txt AC 1 ms 3492 KiB
00_sample_02.txt AC 1 ms 3532 KiB
01_random_00.txt AC 8 ms 10024 KiB
01_random_01.txt AC 24 ms 25524 KiB
01_random_02.txt AC 23 ms 24176 KiB
01_random_03.txt AC 1 ms 3796 KiB
01_random_04.txt AC 10 ms 11672 KiB
01_random_05.txt AC 12 ms 12824 KiB
01_random_06.txt AC 19 ms 19684 KiB
01_random_07.txt AC 17 ms 19256 KiB
01_random_08.txt AC 2 ms 4464 KiB
01_random_09.txt AC 18 ms 19292 KiB
01_random_10.txt AC 22 ms 25588 KiB
01_random_11.txt AC 22 ms 25472 KiB
01_random_12.txt AC 22 ms 25568 KiB
01_random_13.txt AC 23 ms 25468 KiB
01_random_14.txt AC 22 ms 25496 KiB
01_random_15.txt AC 23 ms 25488 KiB
01_random_16.txt AC 22 ms 25456 KiB
01_random_17.txt AC 22 ms 25568 KiB
01_random_18.txt AC 22 ms 25508 KiB
01_random_19.txt AC 22 ms 25572 KiB
01_random_20.txt AC 4 ms 3692 KiB
01_random_21.txt AC 4 ms 3684 KiB
01_random_22.txt AC 22 ms 25524 KiB
01_random_23.txt AC 1 ms 3524 KiB
01_random_24.txt AC 1 ms 3536 KiB
01_random_25.txt AC 1 ms 3500 KiB
01_random_26.txt AC 1 ms 3440 KiB
01_random_27.txt AC 4 ms 3688 KiB
01_random_28.txt AC 4 ms 3612 KiB
01_random_29.txt AC 4 ms 3604 KiB
01_random_30.txt AC 4 ms 3592 KiB
01_random_31.txt AC 4 ms 3620 KiB
01_random_32.txt AC 4 ms 3560 KiB
01_random_33.txt AC 4 ms 3816 KiB
01_random_34.txt AC 4 ms 3692 KiB
01_random_35.txt AC 4 ms 3620 KiB
01_random_36.txt AC 4 ms 3592 KiB
01_random_37.txt AC 22 ms 25528 KiB
01_random_38.txt AC 22 ms 25508 KiB
01_random_39.txt AC 22 ms 25476 KiB