제출 #135438

#제출 시각아이디문제언어결과실행 시간메모리
135438MAMBAPaint By Numbers (IOI16_paint)C++17
59 / 100
3 ms380 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; #define rep(i , j ,k) for(int i = j; i < (int)k; i++) typedef vector<int> vi; const int N = 1e5 + 10; bitset<102> dp[N] , pd[N]; string solve_puzzle(string s, vi c) { int n = s.size(); int k = c.size(); { int last = -1; rep(i , 0 , n) { dp[i][0] = true; if (s[i] == '_') last = i; rep(j , 1 , k + 1) { if (i) dp[i][j] = dp[i - 1][j]; int p = i - c[j - 1]; if (last <= p) { if (p == -1) dp[i][j] = j == 1; else if (p == 0) dp[i][j] = j == 1 && s[p] != 'X'; else dp[i][j] = s[p] != 'X' && dp[p - 1][j - 1]; } } } } { int last = n; for (int i = n - 1; ~i; i--) { pd[i][k + 1] = true; if (s[i] == '_') last = i; rep(j , 1 , k + 1) { int p = i + c[j - 1]; if (i + 1 < n) pd[i][j] = pd[i + 1][j]; if (p <= last) { if (p == n) pd[i][j] = j == k; else if (p == n - 1) pd[i][j] = j == k && s[p] != 'X'; else pd[i][j] = s[p] != 'X' && pd[p + 1][j + 1]; } } } } vi cnt(n + 1); rep(j , 1 , k + 1) { int last = -1; rep(i , 0 , n) { if (s[i] == '_') last = i; int p = i - c[j - 1]; if (last <= p) { bool flag = true; if (flag && p == -1) { if (j > 1) flag = false; } else if (flag) { if (s[p] == 'X') flag = false; if (p == 0) { if (j > 1) flag = false; } else if (!dp[p - 1][j - 1]) flag = false; } p = i + 1; if (p == n) { if (j < k) flag = false; } else if (flag) { if (s[p] == 'X') flag = false; if (p == n - 1) { if (j < k) flag = false; } else if (!pd[p + 1][j + 1]) flag = false; } if (flag) { cnt[i - c[j - 1] + 1]++; cnt[i + 1]--; } } } } string res; int local = 0; rep(i , 0 , n) { local += cnt[i]; bool A = local > 0; bool B = false; rep(j , 0 , k + 1) { bool C = true; if (i == 0 && j) C = false; if (i == n - 1 && j < k) C = false; if (i && !dp[i - 1][j]) C= false; if (i + 1 < n && !pd[i + 1][j + 1]) C = false; B |= C; } if (s[i] == 'X') B = false; if (A && !B) res.push_back('X'); else if (!A && B) res.push_back('_'); else res.push_back('?'); } return res; }
#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...