제출 #1022997

#제출 시각아이디문제언어결과실행 시간메모리
1022997AmirAli_H1Paint By Numbers (IOI16_paint)C++17
100 / 100
260 ms46020 KiB
// In the name of Allah #include <bits/stdc++.h> #include "paint.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 2e5 + 7; const int maxk = 100 + 4; int n, k; int A[maxn], val[maxk]; int sm0[maxn], sm1[maxn]; bool dp1[maxn][maxk], dp2[maxn][maxk]; int ok0[maxn], ok1[maxn]; string solve_puzzle(string s, vector<int> c) { n = len(s); k = len(c); for (int i = 1; i <= n; i++) { if (s[i - 1] == 'X') A[i] = 1; else if (s[i - 1] == '_') A[i] = 0; else A[i] = -1; sm0[i] = sm0[i - 1] + (A[i] == 0); sm1[i] = sm1[i - 1] + (A[i] == 1); } for (int i = 1; i <= k; i++) val[i] = c[i - 1]; dp1[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { if (A[i] != 1) dp1[i][j] = dp1[i - 1][j]; else dp1[i][j] = 0; if (j >= 1 && i - val[j] >= 0) { if (sm0[i] - sm0[i - val[j]] == 0) { if (i - val[j] == 0) dp1[i][j] |= dp1[i - val[j]][j - 1]; else if (A[i - val[j]] != 1) dp1[i][j] |= dp1[i - val[j] - 1][j - 1]; } } } } dp2[n + 1][k + 1] = 1; for (int i = n; i >= 1; i--) { for (int j = k + 1; j >= 1; j--) { if (A[i] != 1) dp2[i][j] = dp2[i + 1][j]; else dp2[i][j] = 0; if (j <= k && i + val[j] - 1 <= n) { if (sm0[i + val[j] - 1] - sm0[i - 1] == 0) { if (i + val[j] == n + 1) dp2[i][j] |= dp2[i + val[j]][j + 1]; else if (A[i + val[j]] != 1) dp2[i][j] |= dp2[i + val[j] + 1][j + 1]; } } } } for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { if (dp1[i - 1][j] && dp2[i + 1][j + 1]) { ok0[i]++; ok0[i + 1]--; } } } for (int j = 1; j <= k; j++) { for (int i = val[j]; i <= n; i++) { if (sm0[i] - sm0[i - val[j]] != 0) continue; if (i + 1 <= n && A[i + 1] == 1) continue; if (i - val[j] >= 1 && A[i - val[j]] == 1) continue; int j1 = max(i - val[j] - 1, 0); int j2 = min(i + 2, n + 1); if (dp1[j1][j - 1] && dp2[j2][j + 1]) { ok1[i - val[j] + 1]++; ok1[i + 1]--; } } } string res = s; for (int i = 1; i <= n; i++) { ok0[i] += ok0[i - 1]; ok1[i] += ok1[i - 1]; if (res[i - 1] == '.') { if (ok0[i] > 0 && ok1[i] > 0) res[i - 1] = '?'; else if (ok0[i] > 0) res[i - 1] = '_'; else res[i - 1] = 'X'; } } 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...