제출 #63310

#제출 시각아이디문제언어결과실행 시간메모리
63310fallingstarPaint By Numbers (IOI16_paint)C++14
100 / 100
415 ms49120 KiB
#include "paint.h" #include <algorithm> using namespace std; const int N = 2e5 + 2; const int K = 1e2 + 2; int n, k, sumW[N], c[N]; bool canPref[N][K], canSuff[N][K]; string s; bool canBlack[N], canWhite[N]; inline bool GetPref(int i, int j) { if (i <= 0) return j == 0; else return s[i] != 'X' && canPref[i - 1][j]; } inline bool GetSuff(int i, int j) { if (i > n) return j == k + 1; else return s[i] != 'X' && canSuff[i + 1][j]; } void Preprocess() { for (int i = 1; i <= n; ++i) sumW[i] = sumW[i - 1] + (s[i] == '_'); canPref[0][0] = canSuff[n + 1][k + 1] = true; for (int i = 1; i <= n; ++i) for (int j = 0; j <= k; ++j) { // place white canPref[i][j] = canPref[i - 1][j] && s[i] != 'X'; // place black if (j > 0) canPref[i][j] |= i >= c[j] && sumW[i] == sumW[i - c[j]] && GetPref(i - c[j], j - 1); } for (int i = n; i >= 1; --i) for (int j = 1; j <= k + 1; ++j) { // place white canSuff[i][j] = canSuff[i + 1][j] && s[i] != 'X'; // place black if (j > 0) canSuff[i][j] |= i + c[j] - 1 <= n && sumW[i - 1] == sumW[i + c[j] - 1] && GetSuff(i + c[j], j + 1); } } string solve_puzzle(string _s, vector<int> _c) { n = _s.size(), k = _c.size(); s = " " + _s, copy(_c.begin(), _c.end(), c + 1); Preprocess(); for (int i = 1, r = 0; i <= n; ++i) { if (s[i] != 'X') { for (int j = 0; j <= k; ++j) if (canPref[i - 1][j] && canSuff[i + 1][j + 1]) { canWhite[i] = true; break; } } else canBlack[i] = true; if (s[i] != '_') { for (int j = 1; j <= k; ++j) if (GetPref(i - 1, j - 1) && i + c[j] - 1 <= n && sumW[i - 1] == sumW[i + c[j] - 1] && GetSuff(i + c[j], j + 1)) r = max(r, i + c[j] - 1); if (r >= i) canBlack[i] = true; } else canWhite[i] = true; } for (int i = 1; i <= n; ++i) if (canBlack[i] && canWhite[i]) _s[i - 1] = '?'; else if (canBlack[i]) _s[i - 1] = 'X'; else _s[i - 1] = '_'; 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...