Submission #961236

#TimeUsernameProblemLanguageResultExecution timeMemory
961236MinaRagy06Paint By Numbers (IOI16_paint)C++17
90 / 100
2045 ms42972 KiB
#include <bits/stdc++.h> #include "paint.h" #ifdef MINA #include "grader.cpp" #endif using namespace std; #define ll long long const int N = 200'005, K = 105; bool prfdp[N][K], sufdp[N][K]; string solve_puzzle(string s, vector<int> c) { int n = s.size(), k = c.size(); int prf[n + 1]{}; for (int i = 0; i < n; i++) { prf[i + 1] = prf[i] + (s[i] == '_'); } prfdp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { if (j - 1 >= 0) { if (i - c[j - 1] >= 0 && prf[i] - prf[i - c[j - 1]] == 0) { if (j - 1 == 0) { prfdp[i][j] = prfdp[i - c[j - 1]][j - 1]; } else if (s[i - c[j - 1] - 1] != 'X' && i - c[j - 1] - 1 >= 0) { prfdp[i][j] = prfdp[i - c[j - 1] - 1][j - 1]; } } } if (s[i - 1] != 'X') { prfdp[i][j] |= prfdp[i - 1][j]; } } } sufdp[n][k] = 1; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j <= k; j++) { if (j + 1 <= k) { if (i + c[j] <= n && prf[i + c[j]] - prf[i] == 0) { if (j + 1 == k) { sufdp[i][j] = sufdp[i + c[j]][j + 1]; } else if (i + c[j] + 1 <= n && s[i + c[j]] != 'X') { sufdp[i][j] = sufdp[i + c[j] + 1][j + 1]; } } } if (s[i] != 'X') { sufdp[i][j] |= sufdp[i + 1][j]; } } } string ans; ans.resize(n); for (int i = 0; i < n; i++) { if (s[i] != '.') { ans[i] = s[i]; continue; } bool ok[2]{}; for (int j = 0; j < k; j++) { for (int l = i; l >= max(0, i - c[j] + 1); l--) { if (l + c[j] <= n && prf[l + c[j]] - prf[l] == 0) { bool vl = 0, vr = 0; if (j == 0) { vl = prfdp[l][j]; } else if (l - 1 >= 0 && s[l - 1] != 'X') { vl = prfdp[l - 1][j]; } if (j + 1 == k) { vr = sufdp[l + c[j]][j + 1]; } else if (l + c[j] + 1 <= n && s[l + c[j]] != 'X') { vr = sufdp[l + c[j] + 1][j + 1]; } ok[1] |= vl && vr; } } } // cout << prfdp[i][0] << ' ' << sufdp[i + 1][0] << '\n'; for (int j = 0; j <= k; j++) { ok[0] |= prfdp[i][j] && sufdp[i + 1][j]; } if (ok[0] && ok[1]) { ans[i] = '?'; } else if (ok[0]) { ans[i] = '_'; } else if (ok[1]) { ans[i] = 'X'; } else { assert(0); } } 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...