Submission #147126

#TimeUsernameProblemLanguageResultExecution timeMemory
147126abacabaPaint By Numbers (IOI16_paint)C++14
59 / 100
44 ms26104 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 <cassert> #include "paint.h" 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'); dp[0][0][0] = dp[1][0][0] = true; for(int i = 0; i <= k; ++i) { for(int j = 1; j <= n; ++j) { if(s[j] != '_') { if(i > 0 && j >= a[i] && p[0][j] == p[0][j - a[i]] && s[j - a[i]] != 'X') dp[0][i][j] |= dp[0][i-1][max(0, j - a[i] - 1)]; } if(s[j] != 'X') dp[0][i][j] |= dp[0][i][j-1]; } } reverse(a + 1, a + 1 + k); reverse(s.begin(), s.end()); 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'); for(int i = 0; i <= k; ++i) { for(int j = 1; j <= n; ++j) { if(s[j] != '_') { if(i > 0 && j >= a[i] && p[0][j] == p[0][j - a[i]] && s[j - a[i]] != 'X') dp[1][i][j] |= dp[1][i-1][max(0, j - a[i] - 1)]; } if(s[j] != 'X') dp[1][i][j] |= dp[1][i][j-1]; } } for(int j = n + 1; j <= n + 3; ++j) dp[1][0][j] |= dp[1][0][j-1]; reverse(dp[1], dp[1] + k + 2); reverse(a + 1, a + 1 + k); reverse(s.begin(), s.end()); 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'); for(int i = 0; i <= k + 1; ++i) reverse(dp[1][i], dp[1][i] + n + 2); for(int i = 0; i <= k; ++i) for(int j = 1; j <= n; ++j) if(dp[0][i][j-1] && s[j] != 'X' && dp[1][i+1][j+1]) ++pref[0][j]; for(int i = 1; i <= k; ++i) { for(int j = 1; j + a[i] - 1 <= n; ++j) { if(p[0][j + a[i] - 1] == p[0][j-1] && s[j-1] != 'X' && s[j + a[i]] != 'X' && dp[1][i+1][j + a[i] + 1] && dp[0][i-1][max(j-2, 0)]) { ++pref[1][j]; --pref[1][j + a[i]]; } } } 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...