Submission #146902

#TimeUsernameProblemLanguageResultExecution timeMemory
146902abacabaPaint By Numbers (IOI16_paint)C++14
32 / 100
3 ms760 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 = 2e5 + 5; const int K = 1e2 + 5; int n, k, p[2][N], a[K], pref[2][N]; bool used[K][N], dp[K][N]; bool rec(int pos, int block) { if(used[block][pos]) return dp[block][pos]; if(block == k) { if(p[1][n] == p[1][pos + a[block] - 1]) return dp[block][pos] = true; return dp[block][pos] = false; } used[block][pos] = true; for(int i = pos + a[block] + 1; i + a[block + 1] - 1 <= n; ++i) { if(p[1][i-1] != p[1][pos + a[block] - 1]) break; if(p[0][i + a[block+1] - 1] == p[0][i-1] && rec(i, block + 1)) return dp[block][pos] = true; } return dp[block][pos]; } string solve_puzzle(string s, vector<int> c) { string ans = ""; n = s.size(); k = c.size(); s = '#' + s; 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) a[i+1] = c[i]; for(int i = 1; !p[1][i-1] && i + a[1] - 1 <= n; ++i) if(p[0][i + a[1] - 1] == p[0][i-1]) rec(i, 1); for(int i = 1; i <= n; ++i) for(int j = 1; j <= k; ++j) { if(dp[j][i]) { if(j == 1) ++pref[0][1], --pref[0][i]; if(j == k) ++pref[0][a[j] + i]; ++pref[1][i]; --pref[1][a[j] + i]; ++pref[0][i - 1]; --pref[0][i]; ++pref[0][a[j] + i]; --pref[0][a[j] + i + 1]; } } for(int i = 1; i <= n; ++i) { pref[0][i] += pref[0][i-1] + (s[i] == '_'); pref[1][i] += pref[1][i-1] + (s[i] == 'X'); } for(int i = 1; i <= n; ++i) { 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...