Submission #287148

#TimeUsernameProblemLanguageResultExecution timeMemory
287148SamAndPaint By Numbers (IOI16_paint)C++17
100 / 100
723 ms84468 KiB
#include "paint.h" #include <cstdlib> #include <bits/stdc++.h> using namespace std; #define m_p make_pair #define fi first #define se second #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() const int N = 200005, K = 103; int n; string a; int k; vector<int> c; bool p[N][K][2], s[N][K][2]; void stg(bool dp[N][K][2]) { for (int i = 0; i <= n; ++i) { for (int j = 0; j <= k; ++j) { for (int z = 0; z < 2; ++z) dp[i][j][z] = false; } } int p[N] = {}; dp[0][0][0] = true; for (int i = 1; i <= n; ++i) { p[i] = p[i - 1]; if (a[i] == '_') p[i]++; } for (int i = 0; i < n; ++i) { for (int j = 0; j <= k; ++j) { for (int z = 0; z < 2; ++z) { if (!dp[i][j][z]) continue; if (a[i + 1] != 'X') dp[i + 1][j][0] = true; if (!z) { if (j != k) { if (i + c[j + 1] <= n) { if (p[i + c[j + 1]] - p[i] == 0) { dp[i + c[j + 1]][j + 1][1] = true; } } } } } } } } bool z1[N], z2[N]; int q[N]; std::string solve_puzzle(std::string s_, std::vector<int> c_) { n = sz(s_); a = s_; k = sz(c_); c = c_; reverse(all(a)); a += '@'; reverse(all(a)); reverse(all(c)); c.push_back(0); reverse(all(c)); stg(p); reverse(all(a)); a.pop_back(); reverse(all(a)); a += '@'; reverse(all(a)); reverse(all(c)); c.pop_back(); reverse(all(c)); c.push_back(0); reverse(all(c)); stg(s); reverse(all(a)); a.pop_back(); reverse(all(a)); a += '@'; reverse(all(a)); reverse(all(c)); c.pop_back(); reverse(all(c)); c.push_back(0); reverse(all(c)); for (int i = 0, j = n + 1; i <= j; ++i, --j) { for (int u = 0; u <= k; ++u) { swap(s[i][u], s[j][u]); } } for (int u = 1; u <= n + 1; ++u) { for (int i = 0, j = k + 1; i <= j; ++i, --j) { swap(s[u][i], s[u][j]); } } for (int j = 1; j <= k; ++j) { for (int l = 1; l <= n - c[j] + 1; ++l) { int r = l + c[j] - 1; if (p[l - 1][j - 1][0] && s[l][j][1]) { ++q[l]; --q[r + 1]; } } } for (int i = 1; i <= n; ++i) { q[i] += q[i - 1]; if (q[i]) z1[i] = true; else z1[i] = false; } for (int i = 1; i <= n; ++i) { z2[i] = false; for (int j = 0; j <= k; ++j) { if (p[i][j][0] && s[i][j + 1][0]) { z2[i] = true; break; } } } string ans; for (int i = 1; i <= n; ++i) { if (a[i] != '.') { ans.push_back(a[i]); continue; } if (z1[i] && z2[i]) ans.push_back('?'); else if (z1[i]) ans.push_back('X'); else ans.push_back('_'); } 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...