Submission #146949

#TimeUsernameProblemLanguageResultExecution timeMemory
146949abacabaPaint By Numbers (IOI16_paint)C++14
7 / 100
3 ms1400 KiB
#include <iostream> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <cstdlib> #include <deque> #include "paint.h" #include <cassert> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> const int N = 5e5 + 5; const int K = 1e2 + 5; int n, k, p[2][N], a[K], pref[2][N]; bool dp[2][K][N]; string solve_puzzle(string s, vector<int> c) { string ans = ""; n = s.size(); k = c.size(); s = '#' + s + '.'; for(int i = 0; i < k; ++i) a[i + 1] = c[i]; for(int i = 1; i <= n; ++i) p[0][i] = p[0][i-1] + (s[i] == '_'), p[1][i] = p[1][i-1] + (s[i] == 'X'); memset(dp[0][0], 1, sizeof(dp[0][0])); memset(dp[1][k+1], 1, sizeof(dp[1][k+1])); for(int j = 1; j <= k; ++j) for(int i = 1; i <= n; ++i) { if(s[i] != 'X') dp[0][j][i] |= dp[0][j][i-1]; if(s[i] != '_' && i >= a[j] && p[0][i] == p[0][i - a[j]]) { if(i > a[j] && s[i - a[j] - 1] == 'X') continue; dp[0][j][i] |= dp[0][j-1][max(0, i - a[j] - 1)]; } } for(int j = k; j; --j) for(int i = n; i; --i) { if(s[i] != 'X') dp[1][j][i] |= dp[1][j][i+1]; if(i + a[j] - 1 <= n && s[i] != '_' && p[0][i-1] == p[0][i + a[j] - 1]) { if(i + a[j] <= n && s[i + a[j]] == 'X') continue; dp[1][j][i] |= dp[1][j+1][min(n + 1, i + a[j] + 1)]; } } for(int i = 1; i <= n; ++i) for(int j = 2; j < k; ++j) if(dp[0][j][i-1] && dp[1][j+1][i+1] && s[i] != 'X') ++pref[0][i]; for(int i = 1; i <= n; ++i) { if(p[1][n] == p[1][i] && dp[0][k][i-1] && s[i] != 'X') ++pref[0][i]; if(!p[1][i-1] && dp[1][1][i+1] && s[i] != 'X') ++pref[0][i]; } for(int i = a[1]; i <= n; ++i) { if(!p[1][i-1] && p[0][i-1] == p[0][i + a[1] - 1] && s[i + a[1]] != 'X' && dp[1][2][i + a[1] + 1]) ++pref[1][i], --pref[1][i + a[1]]; } if(k == 1) { for(int i = 1; i + a[1] - 1 <= n; ++i) { if(!p[1][i-1] && p[1][n] == p[1][i + a[1] - 1] && p[0][i + a[1] - 1] == p[0][i - 1]) { ++pref[1][i]; --pref[1][i + a[1]]; } } } else { for(int i = 1; i + a[1] - 1 <= n; ++i) { if(i + a[1] > n || s[i + a[1]] != 'X') { if(!p[1][i-1] && p[0][i + a[1] - 1] == p[0][i - 1] && dp[1][2][i + a[1] + 1]) { ++pref[1][i]; --pref[1][i + a[1]]; } } } for(int i = 1; i + a[k] - 1 <= n; ++i) { if(i + a[k] > n || s[i + a[k]] != 'X') { if(p[1][n] == p[1][i + a[k]] && p[0][i + a[k] - 1] == p[0][i - 1] && dp[0][k-1][max(0, i-2)]) { ++pref[1][i]; --pref[1][i + a[k]]; } } } } for(int j = 2; j < k; ++j) { for(int i = 1; i + a[j] - 1 <= n; ++i) { if(s[i-1] != 'X' && s[i + a[j]] != 'X' && p[0][i + a[j] - 1] == p[0][i - 1]) { if(dp[1][j + 1][i + a[j] + 1] && dp[0][j-1][i-1]) { ++pref[1][i]; --pref[1][i + a[j]]; } } } } for(int i = 1; i <= n; ++i) { pref[1][i] += pref[1][i-1]; if(pref[1][i] && pref[0][i]) ans += '?'; else if(pref[1][i]) ans += 'X'; else ans += '_'; } 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...