제출 #287005

#제출 시각아이디문제언어결과실행 시간메모리
287005Shafin666Paint By Numbers (IOI16_paint)C++14
0 / 100
1 ms384 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 lft[maxn], rgt[maxn]; 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] + (s[i-1] == '_'); for(int i = 1; i <= n; i++) crs[i] = crs[i-1] + (s[i-1] == 'X'); int aux[maxn]; aux[0] = 1; dp1[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) aux[i] = 1, dp1[i][0] = 1; for(int j = 1, pos = 0; j <= k; j++) { for(int i = 1; i <= n; i++) { if(j > 1) dp1[i][j] = aux[i - c[j-1] - 1] & okx(i - c[j-1] + 1, i); else dp1[i][j] = aux[i - c[j-1]] & okx(i - c[j-1] + 1, i); dp1[i][j] = dp1[i][j] & (crs[max(i - c[j-1] - 1, 0)] == crs[pos]); } aux[0] = 0; for(int i = 1; i <= n; i++) { aux[i] = max(aux[i-1], dp1[i][j]); if(dp1[i][j]) pos = i; } } 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] == '_'); for(int i = 1; i <= n; i++) crs[i] = crs[i-1] + (str[i-1] == 'X'); aux[0] = 1; dp2[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) aux[i] = 1, dp2[i][0] = 1; for(int j = 1, pos = 0; j <= k; j++) { for(int i = 1; i <= n; i++) { if(j > 1) dp2[i][j] = aux[i - c[j-1] - 1] & okx(i - c[j-1] + 1, i); else dp2[i][j] = aux[i - c[j-1]] & okx(i - c[j-1] + 1, i); dp2[i][j] = dp2[i][j] & (crs[max(i - c[j-1] - 1, 0)] == crs[pos]); } aux[0] = 0; for(int i = 1; i <= n; i++) { aux[i] = max(aux[i-1], dp2[i][j]); if(dp2[i][j]) pos = i; } } for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) dp2[i][j] = max(dp2[i-1][j], dp2[i][j]); } for(int j = 0; j <= k; j++) { for(int i = 1; 2*i <= n; i++) swap(dp2[i][j], dp2[n-i+1][j]); dp2[n+1][0] = 1; } reverse(c.begin(), c.end()); for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { // if(i == n) x[i] = max(x[i], dp1[i][j] & dp2[i+1][k-j]); // else x[i] = max(x[i], dp1[i][j] & dp2[i+2][k-j]); if(i == n) { if(dp1[i][j] & dp2[i+1][k-j]) x[i+1]--, x[i - c[j-1] + 1]++; } else { if(dp1[i][j] && dp2[i+2][k-j]) x[i+1]--, x[i - c[j-1] + 1]++; } } } for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) dp1[i][j] = max(dp1[i-1][j], dp1[i][j]); } for(int i = 1; i <= n; i++) { for(int j = 0; j <= k; j++) { y[i] = max(y[i], dp1[i-1][j] & dp2[i+1][k-j]); } } // for(int j = 0; j <= k; j++) { // for(int i = 0; i <= n; i++) // cout << dp1[i][j] << " "; // cout << endl; // } cout << endl; // for(int j = 0; j <= k; j++) { // for(int i = 0; i <= n; i++) // cout << dp2[i][j] << " "; // cout << endl; // } cout << endl; for(int i = 1; i <= n; i++) x[i] += x[i-1]; for(int i = 1; i <= n; i++) x[i] = (x[i] > 0); // for(int i = 1; i <= n; i++) cout << x[i] << " "; cout << endl; // for(int i = 1; i <= n; i++) cout << y[i] << " "; cout << endl; string res = ""; for(int i = 1; i <= n; i++) { if(s[i-1] == 'X') res += "X"; else if(s[i-1] == '_') res += "_"; else if(x[i] && y[i]) res += "?"; else if(y[i]) res += "_"; else 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...