제출 #287500

#제출 시각아이디문제언어결과실행 시간메모리
287500Shafin666Paint By Numbers (IOI16_paint)C++14
90 / 100
2016 ms318348 KiB
#include <bits/stdc++.h> #define pb push_back #define pii pair<ll, ll> #define nyan "(=^・ω・^=)" #define read_input freopen("in.txt","r", stdin) #define print_output freopen("out.txt","w", stdout) typedef long long ll; typedef long double ld; using namespace std; const int maxn = 2e5+10, maxk = 103; int n, k; int dp1[maxn][maxk], dp2[maxn][maxk]; int dash[maxn], crs[maxn]; int p1[maxn][maxk], p2[maxn][maxk]; string str; int x[maxn], y[maxn]; bool okx(int l, int r) { if(l >= 2 && str[l-2] == 'X') return 0; if(r < n && str[r] == 'X') return 0; return (dash[r] - dash[l-1] == 0); } std::string solve_puzzle(std::string s, std::vector<int> c) { n = s.length(); str = s; k = c.size(); for(int i = 1; i <= n; i++) { dash[i] = dash[i-1] + (str[i-1] == '_'); crs[i] = crs[i-1] + (str[i-1] == 'X'); } dp1[0][0] = 1; p1[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) p1[i][0] = 1; for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) { int f1 = p1[i-1][j], f2; if(i < c[j-1]) f2 = 0; else if(j > 1) f2 = p1[i - c[j-1] - 1][j-1] & okx(i - c[j-1] + 1, i); else f2 = p1[i - c[j-1]][j-1] & okx(i - c[j-1] + 1, i); if(str[i-1] == '_') p1[i][j] = f1; else if(str[i-1] == 'X') p1[i][j] = f2; else p1[i][j] = f1 | f2; dp1[i][j] = f2; dp1[i][0] = p1[i][0]; } } reverse(str.begin(), str.end()); reverse(c.begin(), c.end()); for(int i = 1; i <= n; i++) { dash[i] = dash[i-1] + (str[i-1] == '_'); crs[i] = crs[i-1] + (str[i-1] == 'X'); } dp2[0][0] = 1; p2[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) p2[i][0] = 1; for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) { int f1 = p2[i-1][j], f2; if(i < c[j-1]) f2 = 0; else if(j > 1) f2 = p2[i - c[j-1] - 1][j-1] & okx(i - c[j-1] + 1, i); else f2 = p2[i - c[j-1]][j-1] & okx(i - c[j-1] + 1, i); if(str[i-1] == '_') p2[i][j] = f1; else if(str[i-1] == 'X') p2[i][j] = f2; else p2[i][j] = f1 | f2; dp2[i][j] = f2; dp2[i][0] = p2[i][0]; } } for(int j = 0; j <= k; j++) { for(int i = 1; 2 * i <= n; i++) { swap(dp2[i][j], dp2[n-i+1][j]); swap(p2[i][j], p2[n-i+1][j]); } } p2[n+1][0] = p2[n+2][0] = 1; dp2[n+1][0] = 1; reverse(c.begin(), c.end()); for(int i = 1; i <= n; i++) { if(s[i-1] == '_') continue; for(int j = 1; j <= k; j++) { if(dp1[i][j] & p2[i+2][k-j]) { x[i+1]--; x[i - c[j-1] + 1]++; } } } for(int i = 1; i <= n; i++) { if(s[i-1] == 'X') continue; for(int j = 0; j <= k; j++) { y[i] = max(y[i], p1[i-1][j] & p2[i+1][k-j]); } } for(int i = 1; i <= n; i++) x[i] += x[i-1]; for(int i = 1; i <= n; i++) x[i] = (x[i] > 0); string res = ""; for(int i = 1; i <= n; i++) { if(s[i-1] == 'X') res.pb('X'); //res += "X"; else if(s[i-1] == '_') res.pb('_'); //res += "_"; else if(x[i] && y[i]) res.pb('?'); //res += "?"; else if(y[i]) res.pb('_'); //res += "_"; else res.pb('X'); //res += "X"; } return res; }
#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...