제출 #562868

#제출 시각아이디문제언어결과실행 시간메모리
562868elazarkorenPaint By Numbers (IOI16_paint)C++17
80 / 100
2088 ms460 KiB
#include "paint.h" #include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; const int MAX_N = 5005; const int MAX_K = 105; bitset<MAX_K> dp[MAX_N]; int n, k; int next_bad[MAX_N]; bool Check(string &s, vi &c, int start) { for (int i = start; i < n; i++) { dp[i].reset(); } int ex = n; next_bad[n] = n; for (int i = n - 1; i >= 0; i--) { next_bad[i] = next_bad[i + 1]; if (s[i] == 'X') ex = i; else if (s[i] == '_') next_bad[i] = i; } for (int i = start; i < n; i++) { if (s[i] != 'X' && i) { dp[i] = dp[i - 1]; } if (s[i] == '_') continue; for (int j = 0, sum = -1; j < k; j++) { sum += c[j] + 1; if (dp[i][j]) continue; if (sum > i + 1) break; bool b = i - c[j] + 1 < 0 || next_bad[i - c[j] + 1] > i; if (b && !j) { dp[i][j] = ex > i - c[j]; } else if (b && (i - c[j] < 0 || s[i - c[j]] != 'X') && (i - c[j] <= 0 || dp[i - c[j] - 1][j - 1])) { dp[i][j] = true; } } } return dp[n - 1][k - 1]; } std::string solve_puzzle(std::string s, std::vector<int> c) { n = s.size(); k = c.size(); string ans(n, '?'); int ex = n; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'X') ex = i; } for (int i = 0; i < n; i++) { if (s[i] != '.') ans[i] = s[i]; else { s[i] = '_'; bool b1 = Check(s, c, 0); s[i] = 'X'; bool b2 = Check(s, c, 0); s[i] = '.'; if (b1 && !b2) ans[i] = s[i] = '_'; else if (!b1 && b2) { ans[i] = s[i] = 'X'; chkmin(ex, i); } } for (int j = 0; j < k; j++) dp[i].reset(); // if (s[i] != 'X') { // if (i) { // for (int j = 0; j < k; j++) { // dp[i][j] = dp[i - 1][j]; // } // } // } // if (s[i] == '_') continue; // for (int j = 0, sum = -1; j < k; j++) { // sum += c[j] + 1; // if (sum > i + 1) break; // bool b = i - c[j] + 1 < 0 || next_bad[i - c[j] + 1] > i; // if (b && !j) { // dp[i][j] |= ex > i - c[j]; // } else if (b && (i - c[j] < 0 || s[i - c[j]] != 'X') && (i - c[j] <= 0 || dp[i - c[j] - 1][j - 1])) { // dp[i][j] = true; // } // } } 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...