제출 #67772

#제출 시각아이디문제언어결과실행 시간메모리
67772TalantPaint By Numbers (IOI16_paint)C++17
90 / 100
2078 ms170260 KiB
#include "paint.h" //#include "grader.cpp" #include <bits/stdc++.h> #define pb push_back #define sc second #define fr first #define mk make_pair using namespace std; const int N = (2e5 + 5); const int inf = (1e9 + 7); int n,m; int b[N],w[N]; int dp[N][105]; int inv[N][105]; int u[N][3]; string ans; string solve_puzzle(string s, vector<int> c) { n = (int)s.size(); m = (int)c.size(); dp[0][0] = 1; for (int i = 1; i <= n; i ++) { b[i] = b[i - 1]; w[i] = w[i - 1]; if (s[i - 1] == 'X') b[i] ++; if (s[i - 1] == '_') w[i] ++; if (!b[i]) dp[i][0] = 1; } for (int i = n; i >= 1; i --){ if (b[n] - b[i - 1] == 0) inv[i][0] = 1; inv[i + n][0] = 1; } for (int j = 1; j <= m; j ++) { for (int i = n; i >= 1; i --) { if (s[i - 1] == '_') inv[i][j] = inv[i + 1][j]; else if (s[i - 1] == 'X') { if (i + c[m - j] - 1 <= n && w[i + c[m - j] - 1] - w[i - 1] == 0 && s[i + c[m - j] - 1] != 'X') inv[i][j] = inv[i + c[m - j] + 1][j - 1]; } else { inv[i][j] |= inv[i + 1][j]; if (i + c[m - j] - 1 <= n && w[i + c[m - j] - 1] - w[i - 1] == 0 && s[i + c[m - j] - 1] != 'X') inv[i][j] |= inv[i + c[m - j] + 1][j - 1]; } } } for (int j = 0; j <= m; j ++) { for (int i = 1; i <= n; i ++) { if (j > 0) { if (s[i - 1] == '_') dp[i][j] = dp[i - 1][j]; else if (s[i - 1] == 'X') { if (i - c[j - 1] >= 0 && w[i] - w[i - c[j - 1]] == 0) { if (i - c[j - 1] - 1 < 0) { if (j - 1 == 0) dp[i][j] = 1; } else { if (s[i - c[j - 1] - 1] != 'X') dp[i][j] = dp[i - c[j - 1] - 1][j - 1]; } } } else { dp[i][j] |= dp[i - 1][j]; if (i - c[j - 1] >= 0 && w[i] - w[i - c[j - 1]] == 0) { if (i - c[j - 1] - 1 < 0) { if (j - 1 == 0) dp[i][j] |= 1; } else { if (s[i - c[j - 1] - 1] != 'X') dp[i][j] |= dp[i - c[j - 1] - 1][j - 1]; } } } } if (s[i - 1] != 'X' && dp[i - 1][j] && inv[i + 1][m - j]) u[i][1] = 1; if (j == 0) continue; if (w[i + c[j - 1] - 1] - w[i - 1] == 0 && (i == 1 || s[i - 2] != 'X') && (s[i + c[j - 1] - 1] != 'X') && ((i == 1 && j - 1 == 0) || dp[i - 2][j - 1]) && (inv[i + c[j - 1] + 1][m - j])) { u[i][2] ++,u[i + c[j - 1]][2] --; } } } for (int j = 1; j <= n; j ++) { u[j][2] += u[j - 1][2]; if (u[j][1] && u[j][2]) ans += '?'; else if (u[j][1]) 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...