Submission #64794949


Source Code Expand

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


template<typename T>
vector<pair<T, int>> RLE(vector<T> a){
    int n = a.size();
    T ls = a[0];
    int cnt = 1;
    vector<pair<T, int>> ret;
    for(int i = 1; i < n; i++){
        if(ls != a[i]){
            ret.push_back({ls, cnt});
            ls = a[i];
            cnt = 0;
        }
        cnt++;
    }
    ret.push_back({ls, cnt});
    return ret;
}

int main(){
    int N, K; cin >> N >> K;
    vector<char> S(N);
    for(int i = 0; i < N; i++)cin >> S[i];
    int mx = 0, maru = 0;
    for(int i = 0; i < N; i++){
        if(S[i] != '?'){
            if(S[i] == 'o'){
                mx++;
                maru++;
            }
        }
        else if((i > 0 && S[i - 1] == 'o') || (i < N - 1 && S[i + 1] == 'o')){
            S[i] = '.';
        }
    }
    vector<pair<char, int>> R = RLE(S);
    for(auto [c, a] : R){
        if(c == '?')mx += (a + 1)/2;
    }
    string T = "";
    for(auto [c, a] : R){
        if(c != '?')T += string(a, c);
        else if(maru == K)T += string(a, '.');
        else if(a % 2 == 0)T += string(a, '?');
        else if(mx == K){
            for(int i = 0; i < a; i++){
                if(i % 2 == 0)T += 'o';
                else T += '.';
            }
        }
        else if(mx > K)T += string(a, '?');
    }
    cout << T << endl;
}

Submission Info

Submission Time
Task D - Logical Filling
User iphi7
Language C++ 23 (gcc 12.2)
Score 400
Code Size 1472 Byte
Status AC
Exec Time 13 ms
Memory 5688 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 43
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KiB
00_sample_01.txt AC 1 ms 3504 KiB
00_sample_02.txt AC 1 ms 3564 KiB
01_random_00.txt AC 5 ms 3980 KiB
01_random_01.txt AC 13 ms 5688 KiB
01_random_02.txt AC 12 ms 5568 KiB
01_random_03.txt AC 1 ms 3520 KiB
01_random_04.txt AC 6 ms 3964 KiB
01_random_05.txt AC 6 ms 3968 KiB
01_random_06.txt AC 10 ms 4608 KiB
01_random_07.txt AC 10 ms 4528 KiB
01_random_08.txt AC 2 ms 3760 KiB
01_random_09.txt AC 10 ms 4492 KiB
01_random_10.txt AC 11 ms 4276 KiB
01_random_11.txt AC 11 ms 4360 KiB
01_random_12.txt AC 10 ms 4352 KiB
01_random_13.txt AC 10 ms 4300 KiB
01_random_14.txt AC 11 ms 4516 KiB
01_random_15.txt AC 10 ms 4360 KiB
01_random_16.txt AC 10 ms 4304 KiB
01_random_17.txt AC 11 ms 4520 KiB
01_random_18.txt AC 10 ms 4364 KiB
01_random_19.txt AC 11 ms 4292 KiB
01_random_20.txt AC 11 ms 5584 KiB
01_random_21.txt AC 9 ms 3736 KiB
01_random_22.txt AC 9 ms 3756 KiB
01_random_23.txt AC 1 ms 3536 KiB
01_random_24.txt AC 1 ms 3500 KiB
01_random_25.txt AC 1 ms 3548 KiB
01_random_26.txt AC 1 ms 3480 KiB
01_random_27.txt AC 11 ms 4636 KiB
01_random_28.txt AC 11 ms 4544 KiB
01_random_29.txt AC 11 ms 4672 KiB
01_random_30.txt AC 11 ms 4668 KiB
01_random_31.txt AC 11 ms 4600 KiB
01_random_32.txt AC 11 ms 4528 KiB
01_random_33.txt AC 11 ms 4596 KiB
01_random_34.txt AC 12 ms 4760 KiB
01_random_35.txt AC 11 ms 4516 KiB
01_random_36.txt AC 11 ms 4672 KiB
01_random_37.txt AC 9 ms 3756 KiB
01_random_38.txt AC 10 ms 3744 KiB
01_random_39.txt AC 9 ms 3700 KiB