제출 #957067

#제출 시각아이디문제언어결과실행 시간메모리
957067mariaclaraPaint By Numbers (IOI16_paint)C++17
100 / 100
174 ms85664 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<int,int,int> trio; typedef pair<int,int> pii; const int MAXN = 2e5+5; const int MOD = 1e9+7; #define all(x) x.begin(), x.end() #define mk make_pair #define pb push_back #define f first #define s second int pref[MAXN], pref2[MAXN]; bool dpL[2][MAXN][105], dpR[2][MAXN][105], val[2][MAXN]; string solve_puzzle(string a, vector<int> c) { int n = a.size(), k = c.size(); for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + (a[i-1] == '_'); dpL[0][0][0] = 1; for(int i = 1; i <= n; i++) { for(int j = 0; j <= k; j++) { if(a[i-1] != 'X') dpL[0][i][j] = dpL[0][i-1][j] or dpL[1][i-1][j]; if(j and i >= c[j-1] and pref[i] == pref[i-c[j-1]]) dpL[1][i][j] = dpL[0][i-c[j-1]][j-1]; } } dpR[0][n+1][k] = 1; for(int i = n; i >= 1; i--) { for(int j = 0; j <= k; j++) { if(a[i-1] != 'X') dpR[0][i][j] = dpR[0][i+1][j]; if(a[i-1] != '_') dpR[1][i][j] = dpR[0][i+1][j]; if(a[i-1] != 'X' and j<k and i + c[j] <= n+1 and pref[i] == pref[i+c[j]]) dpR[0][i][j] |= dpR[1][i+c[j]][j+1]; if(dpL[0][i][j] and dpR[0][i][j]) val[0][i] = 1; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { if(i >= c[j-1] and pref[i] == pref[i-c[j-1]] and dpL[0][i-c[j-1]][j-1] and dpR[1][i][j]) pref2[i-c[j-1]+1]++, pref2[i+1]--; } } for(int i = 1; i <= n; i++) { pref2[i] += pref2[i-1]; if(pref2[i]) val[1][i] = 1; } string ans; for(int i = 1; i <= n; i++) { if(val[0][i] and val[1][i]) ans += '?'; else if(val[0][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...