제출 #582731

#제출 시각아이디문제언어결과실행 시간메모리
582731MadokaMagicaFanPaint By Numbers (IOI16_paint)C++14
7 / 100
1 ms420 KiB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

#define all(v)          v.begin(),v.end()
#define sort(v)         sort(all(v))
#define endl            '\n'
#define forn(i,n)       for(int i = 0; i < n; ++i)
#define forbe(i,b,e)    for(int i = b; i < e; ++i)
#define forr(i,n)       for(int i = n-1; i >= 0; --i)
#define sz(v)           ((int)v.size())
#define pb              push_back
#define f               first
#define s               second

struct aib{
    vi f;
    int n;

    aib(int _n) {
        n = _n;
        f.assign(n,0);
    }

    void add(int x, int v) {
        for(;x <n; x  |= (x+1))
            f[x] += v;
    }

    int q(int x) {
        int r = 0;
        for(;x >= 0; x = (x&(x+1))-1)
            r += f[x];
        return r;
    }

    int query(int l, int r) {
        return q(r) - q(l-1);
    }
};

string solve_puzzle(string s, vi c) {
    int n = sz(s);
    int k = sz(c);
    string ans = s;
    vi type(n,0);
    vi pnt(k,0);

    aib tr(n);

    forn(i,n)
        if (s[i] == '_')
            tr.add(i,1);

    int j = 0;

    forn(i,n) {
        if (j == k)
            break;
//        if (tr.query(i,i+c[j]-1) > 0)
//            continue;

        forn(l,c[j]) type[i+l] = 1;
        pnt[j] = i;
        i = i + c[j] + i;
        ++j;
        continue;
    }
    assert(j == k);

    int lm;
    int lp = n+1;
    forr(j,k) {
        lm = lp;
        lp = pnt[j];
        forbe(i,pnt[j], lm - c[j]) {
//            cout << i << ' ' << i + c[j] << ' ' << tr.query(i,i+c[j]) << endl;
//            if (tr.query(i,i+c[j]-1) > 0)
//                continue;
//            cout << j << ' ' << i << ' ' << n <<  endl;
            lp = i;
            forn(l,c[j])
                if (type[l+i] == 0)
                    type[l+i] = 2;
        }

        forbe(i,pnt[j], lp)
            if (type[i] == 1)
                type[i] = 2;
//        cout << pnt[j] << ' ' << lp << endl;
    }

    forn(i,n)
        switch(type[i]) {
            case 0: ans[i] = '_'; break;
            case 1: ans[i] = 'X'; break;
            case 2: ans[i] = '?'; break;
        }
    

    return ans;
}

#ifdef ONPC
void solve() {
    int n, k;
    cin >> k;
    string s;
    cin >> s;
    vi c(k);
    forn(i,k)
        cin >> c[i];
    string ans = solve_puzzle(s,c);

    cout << ans << endl;
}

int main() {
    freopen("in", "r", stdin);
//    ios_base::sync_with_stdio(0);cin.tie(0);
    solve();
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...