Submission #64757554


Source Code Expand

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pii pair<int, int>
#define endl '\n'
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) {
    cerr << ' ' << h;
    dbg_out(t...);
}
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

inline int read() {
    int n=0,f=1,ch=getchar();
    while(ch<'0'||ch>'9') {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') {
        n=n*10+ch-'0';
        ch=getchar();
    }
    return n*f;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k; cin>>n>>k;
    string s; cin>>s;
    int cnt = 0;
    for(int i = 0;i < n;i++)
    {
        if(s[i] == 'o')
        {
            cnt++;
            if(i && s[i - 1] == '?') s[i - 1] = '.';
            else if(i + 1 < n && s[i + 1] == '?') s[i + 1] = '.';
        }
    }
    cnt = k - cnt; // need cnt o
    if(!cnt)
    {
        for(int i = 0;i < n;i++) 
        {
            if(s[i] == '?') cout<<'.';
            else cout<<s[i];
        }
        return 0;
    }
    int i = 0;
    int cnt2 = 0;
    while(i < n)
    {
        // dbg(i);
        if(s[i] == 'o') i++;
        else if(s[i] == '.') i++;
        else 
        {
            int j = i;
            while(j < n && s[j] == '?') j++;
            int len = j - i;
            if(len&1) cnt2 += (len + 1) / 2;
            else cnt2 += len / 2;
            i = j;
        }
    }
    if(cnt == cnt2)
    {
        int i = 0;
        while(i < n)
        {
            // dbg(i);
            if(s[i] == 'o') i++;
            else if(s[i] == '.') i++;
            else 
            {
                int j = i;
                while(j < n && s[j] == '?') j++;
                int len = j - i;
                if(len&1)
                {
                    for(int k = i;k < j;k++) 
                    {
                        if((k - i + 1)&1) s[k] = 'o';
                        else s[k] = '.';
                    }
                }
                i = j;
            }
        }
        for(int i = 0;i < n;i++) cout<<s[i];
    }
    else
    {
        for(int i = 0;i < n;i++)
        {
            cout<<s[i];
        }
    }
    return 0;
}

Submission Info

Submission Time
Task D - Logical Filling
User yunjie
Language C++ 17 (gcc 12.2)
Score 0
Code Size 2966 Byte
Status WA
Exec Time 5 ms
Memory 3676 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 22
WA × 21
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 3472 KiB
00_sample_01.txt AC 1 ms 3408 KiB
00_sample_02.txt AC 1 ms 3464 KiB
01_random_00.txt WA 2 ms 3652 KiB
01_random_01.txt WA 5 ms 3676 KiB
01_random_02.txt WA 4 ms 3596 KiB
01_random_03.txt WA 1 ms 3408 KiB
01_random_04.txt WA 2 ms 3596 KiB
01_random_05.txt WA 3 ms 3608 KiB
01_random_06.txt WA 4 ms 3608 KiB
01_random_07.txt WA 4 ms 3584 KiB
01_random_08.txt WA 1 ms 3500 KiB
01_random_09.txt WA 4 ms 3464 KiB
01_random_10.txt WA 4 ms 3600 KiB
01_random_11.txt WA 4 ms 3672 KiB
01_random_12.txt WA 4 ms 3600 KiB
01_random_13.txt WA 4 ms 3592 KiB
01_random_14.txt WA 3 ms 3596 KiB
01_random_15.txt WA 3 ms 3672 KiB
01_random_16.txt WA 4 ms 3672 KiB
01_random_17.txt WA 4 ms 3640 KiB
01_random_18.txt WA 4 ms 3660 KiB
01_random_19.txt WA 3 ms 3600 KiB
01_random_20.txt AC 3 ms 3600 KiB
01_random_21.txt AC 3 ms 3596 KiB
01_random_22.txt AC 3 ms 3596 KiB
01_random_23.txt AC 1 ms 3476 KiB
01_random_24.txt AC 1 ms 3456 KiB
01_random_25.txt AC 1 ms 3440 KiB
01_random_26.txt AC 1 ms 3596 KiB
01_random_27.txt AC 4 ms 3464 KiB
01_random_28.txt AC 4 ms 3596 KiB
01_random_29.txt AC 4 ms 3584 KiB
01_random_30.txt AC 4 ms 3464 KiB
01_random_31.txt AC 4 ms 3608 KiB
01_random_32.txt AC 4 ms 3584 KiB
01_random_33.txt AC 4 ms 3668 KiB
01_random_34.txt AC 4 ms 3592 KiB
01_random_35.txt AC 4 ms 3596 KiB
01_random_36.txt AC 4 ms 3588 KiB
01_random_37.txt WA 3 ms 3600 KiB
01_random_38.txt AC 3 ms 3604 KiB
01_random_39.txt AC 3 ms 3600 KiB