Submission #288469

#TimeUsernameProblemLanguageResultExecution timeMemory
288469arayiPaint By Numbers (IOI16_paint)C++17
100 / 100
789 ms46840 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; const int N = 2e5 + 30; int n, k; int pr[N]; bool dp[N][111], dp1[N][111]; bool col[N], cl[N]; int sm[N]; int qry(int l, int r) { if(l) return pr[r] - pr[l - 1]; return pr[r]; } bool chk(int i1, int k1) { if(i1 >= 0) return dp[i1][k1]; return k1 == 0; } bool chk1(int i1, int k1) { if(i1 < n) return dp1[i1][k1]; return k1 == k; } string solve_puzzle(string s, vector<int> c) { n = s.length(); k = c.size(); for (int i = 0; i < n; i++) { pr[i] = (s[i] == '_'); if(i) pr[i] += pr[i - 1]; } for (int i = 0; i < n; i++) { if(s[i] == 'X') break; dp[i][0] = 1; } for (int i = 1; i <= k; i++) { for(int j = 0; j < n; j++) { if(c[i - 1] > j + 1) dp[j][i] = 0; else if(qry(j - c[i - 1] + 1, j)) dp[j][i] = 0; else if(j - c[i - 1] >= 0 && s[j - c[i - 1]] == 'X') dp[j][i] = 0; else dp[j][i] = chk(j - c[i - 1] - 1, i - 1); if(s[j] != 'X' && j) dp[j][i] = dp[j][i] | dp[j - 1][i]; } } for(int i = n - 1; i >= 0; i--) { if(s[i] == 'X') break; dp1[i][k] = 1; } for(int i = k - 1; i >= 0; i--) { for(int j = n - 1; j >= 0; j--) { if(c[i] > n - j) dp1[j][i] = 0; else if(qry(j, j + c[i] - 1)) dp1[j][i] = 0; else if(j + c[i] < n && s[j + c[i]] == 'X') dp1[j][i] = 0; else dp1[j][i] = chk1(j + c[i] + 1, i + 1); if(s[j] != 'X') dp1[j][i] = dp1[j][i] | dp1[j + 1][i]; } } for (int i = 0; i < n; i++) { if(s[i] == 'X') continue; for(int j = 0; j <= k; j++) { if(chk(i - 1, j) && chk1(i + 1, j)) cl[i] = 1; } } for (int i = 0; i < k; i++) { int l = 0, r = c[i] - 1; while(r < n) { bool bl = true; if(qry(l, r)) bl = false; else if(l && s[l - 1] == 'X') bl = false; else if(r < n - 1 && s[r + 1] == 'X') bl = false; else if(!chk(l - 2, i)) bl = false; else if(!chk1(r + 2, i + 1)) bl = false; if(bl) sm[l]++, sm[r + 1]--; l++, r++; } } for (int i = 0; i < n; i++) { if(i) sm[i] += sm[i - 1]; col[i] = sm[i]; } for (int i = 0; i < n; i++) { if(s[i] != '.') continue; if(col[i] && cl[i]) s[i] = '?'; else if(col[i]) s[i] = 'X'; else s[i] = '_'; } return s; }
#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...