Submission #101801

#TimeUsernameProblemLanguageResultExecution timeMemory
101801briansuPaint By Numbers (IOI16_paint)C++14
100 / 100
365 ms91548 KiB
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

#include "paint.h"

ll d[MAXn], ans[MAXn];
ll pre[2][MAXn], h[MAXn], fw[MAXn];
bool dpf[MAXn][105][2], dpb[MAXn][105][2];

std::string solve_puzzle(std::string s, std::vector<int> c) {
    int n = SZ(s), k = SZ(c);
    REP(i,n)
    {
        if(s[i] == 'X')d[i+1] = 1;
        else if(s[i] == '_')d[i+1] = 0;
        else d[i+1] = -1;
    }
    REP1(i,n)if(d[i] != -1)pre[d[i]][i]++;
    REP(i,2)REP1(j, n)pre[i][j] += pre[i][j-1];
    REP(i, k)h[i+1] = c[i];
    
    dpf[0][0][0] = 1;
    REP1(i,n)REP(j,k+1)
    {
        // white
        if(d[i] != 1 && (dpf[i-1][j][1] || dpf[i-1][j][0]))dpf[i][j][0] = 1;
        // black
        if(j != 0)if(d[i] != 0 && i >= h[j] && pre[0][i] - pre[0][i - h[j]] == 0 && dpf[i - h[j]][j-1][0])dpf[i][j][1] = 1;
    }
    REP1(i,n)REP(j,k+1)debug(i, j, dpf[i][j][0], dpf[i][j][1]);

    dpb[n+1][k+1][0] = 1;
    for(int i = n;i > 0;i --)REP1(j, k+1)
    {
        // white
        if(d[i] != 1 && (dpb[i+1][j][1] || dpb[i+1][j][0]))dpb[i][j][0] = 1;
        // black
        if(j != k+1)if(d[i] != 0 && n - i + 1 >= h[j] && pre[0][i + h[j] - 1] - pre[0][i-1] == 0 && dpb[i + h[j]][j+1][0])dpb[i][j][1] = 1;
    }
    REP1(i,n)REP(j,k+1)debug(i, j, dpb[i][j][0], dpb[i][j][1]);
    FILL(ans, 0);
    // white
    REP1(i,n)REP(j, k+1)if(dpf[i][j][0] && dpb[i][j+1][0])ans[i] |= 1;

    //black
    FILL(fw, 0);
    REP1(i,n)REP1(j, k)if(i + h[j] - 1 <= n && dpf[i + h[j] - 1][j][1] && dpb[i][j][1])fw[i] = max(fw[i], h[j]);

    ll ct = 0;
    REP1(i, n)
    {
        ct = max(ct, fw[i]);
        if(ct > 0)ans[i] |= 2;
        ct --;
    }
    REP1(i,n)debug(i, fw[i], ans[i]);
    string as = "";
    REP1(i,n)
    {
        if(ans[i] == 1)as.pb('_');
        else if(ans[i] == 2)as.pb('X');
        else as.pb('?');
    }
    return as;
}
#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...