Submission #599854

#TimeUsernameProblemLanguageResultExecution timeMemory
599854balbitPaint By Numbers (IOI16_paint)C++14
100 / 100
438 ms8900 KiB
#include "paint.h" #include <bits/stdc++.h> // #define int ll using namespace std; #define ll long long #define y1 zck_is_king #define pii pair<ll, ll> #define ull unsigned ll #define f first #define s second #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define SQ(x) (x)*(x) #define MN(a,b) a = min(a,(__typeof__(a))(b)) #define MX(a,b) a = max(a,(__typeof__(a))(b)) #define pb push_back #define REP(i,n) for (int i = 0; i<n; ++i) #define RREP(i,n) for (int i = n-1; i>=0; --i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #ifdef BALBIT #define IOS() #define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__); template<typename T> void _do(T &&x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);} #else #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define bug(...) #endif const int iinf = 1e9+10; const ll inf = 0x3f3f3f3f3f3f3f3f; const ll mod = 1e9+7 ; const int maxn = 2e5+5; bitset<maxn> B[2][105]; vector<int> psy, psn; // ps yes, ps no void build(int W, string s, vector<int> c) { // 1-indexed int n = SZ(s); B[W][0][0] = 1; REP1(j,n) { if (s[j-1] == 'X') break; B[W][0][j] = 1; } REP(i, SZ(c)) { REP1(j,n) { if (j - c[i] >= 0 && (psn[j]-psn[j-c[i]]==0) && (j-c[i]==0||s[j-c[i]-1]!='X')) { B[W][i+1][j] = B[W][i+1][j] | B[W][i][max(0,j-c[i]-1)]; } if (s[j-1] != 'X') { B[W][i+1][j] = B[W][i+1][j] | B[W][i+1][j-1]; } } } } std::string solve_puzzle(std::string s, std::vector<int> c) { int n = SZ(s); psy.resize(n+1,0), psn.resize(n+1,0); REP(i, n) { psy[i+1] = psy[i] + (s[i]=='X'); psn[i+1] = psn[i] + (s[i]=='_'); } build(0, s, c); reverse(ALL(s)); reverse(ALL(c)); psy.resize(n+1,0), psn.resize(n+1,0); REP(i, n) { psy[i+1] = psy[i] + (s[i]=='X'); psn[i+1] = psn[i] + (s[i]=='_'); } build(1,s,c); reverse(ALL(s)); reverse(ALL(c)); psy.resize(n+1,0), psn.resize(n+1,0); REP(i, n) { psy[i+1] = psy[i] + (s[i]=='X'); psn[i+1] = psn[i] + (s[i]=='_'); } vector<int> can(n+2); vector<bool> can0(n+1); REP1(i,n) { if (s[i-1]=='.') { REP(tleft, SZ(c)+1) { if (B[0][tleft][i-1] && B[1][SZ(c)-tleft][n-i]) { can0[i] = 1; } } } } REP(i, SZ(c)) { REP1(j,n) { if (j - c[i] >= 0 && (psn[j]-psn[j-c[i]]==0) && (j-c[i]==0||s[j-c[i]-1]!='X')) { if (B[0][i][max(0,j-c[i]-1)] && (j==n||s[j]!='X') && B[1][SZ(c)-1-i][max(0,n-j-1)]) { bug(j-c[i]+1, j); ++can[j-c[i]+1]; --can[j+1]; } } } } string re; REP1(j,n) { can[j] += can[j-1]; bug(j,can0[j],can[j]); if (s[j-1]=='.') { if (can0[j] && can[j]) { re.pb('?'); }else if (can0[j]) re.pb('_'); else re.pb('X'); }else{ re.pb(s[j-1]); } } return re; }
#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...