제출 #364926

#제출 시각아이디문제언어결과실행 시간메모리
364926CSQ31Paint By Numbers (IOI16_paint)C++14
100 / 100
683 ms32864 KiB
//#include "grader.cpp" #include <cstdlib> #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define MOD (ll)(1e9+7) #define INF (ll)(1e18) #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} std::string solve_puzzle(std::string s, std::vector<int> c){ int n = sz(s); int k = sz(c); vector<int>w(n+2),b(n+2); vector<vector<bool>>dpp(n+2,vector<bool>(k+3)),dps(n+2,vector<bool>(k+3)); for(int i=1;i<=n+1;i++){ if(s[i-1] == '_')w[i]++; if(s[i-1] == 'X')b[i]++; b[i]+=b[i-1]; w[i]+=w[i-1]; } dpp[0][0] = 1; for(int i=1;i<=n;i++){ if(!b[i])dpp[i][0] = 1; for(int j=1;j<=k;j++){ int L = i-c[j-1]; bool a = 0,b = 1; a = dpp[i-1][j]; if(L > 0)b = (s[L-1] != 'X'); b= b&((L==0 && j==1) || (L>=1 && dpp[L-1][j-1])); if(L>=0)b= b&(w[i]-w[L] == 0); if(s[i-1] == '_')dpp[i][j] = a; else if(s[i-1] == 'X')dpp[i][j] = b; else dpp[i][j] = (a||b); } } dps[n+1][k+1] = 1; for(int i=n;i>0;i--){ if(!(b[n]-b[i-1]))dps[i][k+1] = 1; for(int j=1;j<=k;j++){ int L = i+c[j-1]; bool a = 0,b = 1; a = dps[i+1][j]; if(L<=n)b = (s[L-1] != 'X'); b= b&((L==n+1 && j==k) || (L<=n && dps[L+1][j+1])); if(L<=n+1)b=b&(w[L-1]-w[i-1] == 0); if(s[i-1] == '_')dps[i][j] = a; else if(s[i-1] == 'X')dps[i][j] = b; else dps[i][j] = (a||b); } }/* for(int i=0;i<=k;i++){ for(int j=1;j<=n;j++){ cout<<dpp[j][i]<<" "; } cout<<'\n'; } cout<<'\n'; for(int i=1;i<=k+1;i++){ for(int j=1;j<=n;j++){ cout<<dps[j][i]<<" "; } cout<<'\n'; } cout<<'\n'; */ vector<bool>canw(n+2,0); vector<ll>canb(n+2); for(int i=1;i<=n;i++){ if(s[i-1] == 'X')continue; for(int j=0;j<=k;j++){ if(dpp[i-1][j] && dps[i+1][j+1])canw[i] = 1; } }//check for white ,this works //to check for black iterate starting point and +1 -1,tedious fuck you for(int i=1;i<=n;i++){ if(s[i-1] == 'W')continue; for(int j=1;j<=k;j++){ int R = i+c[j-1]; bool ok = 1; if(R<=n)ok = s[R-1] != 'X'; ok= ok&((R==n+1 && j==k) || (R<=n && dps[R+1][j+1])); //check right side ok= ok&((i == 1 && j == 1) || (i>1 && dpp[i-2][j-1] && s[i-2] != 'X')); //check left side ok= ok&(R-1<=n && w[R-1] - w[i-1] == 0); //check for no white space if(ok){ canb[i]++; canb[R]--; } } } /* for(int i=1;i<=n;i++)cout<<canw[i]<<" "; cout<<'\n'; for(int i=1;i<=n;i++)cout<<canb[i]<<" "; cout<<'\n'; * */ for(int i=1;i<=n;i++)canb[i]+=canb[i-1]; //for(int i=1;i<=n;i++)cout<<canb[i]<<" "; //cout<<'\n'; string ans; for(int i=1;i<=n;i++){ if(canw[i] && canb[i])ans+="?"; else if(canw[i])ans+="_"; else ans+="X"; } return ans; }
#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...