제출 #147127

#제출 시각아이디문제언어결과실행 시간메모리
147127abacabaPaint By Numbers (IOI16_paint)C++14
100 / 100
465 ms75028 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 + 15; const int K = 1e2 + 15; int n, k, p[2][N], a[K], pref[2][N]; bool dp[2][K][N]; inline void calc(string &s) { p[0][0] = p[1][0]; 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'); } inline void calc_dp(string &s, bool dp[K][N]) { dp[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[i][j] |= dp[i-1][max(0, j - a[i] - 1)]; } if(s[j] != 'X') dp[i][j] |= dp[i][j-1]; } } } 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]; calc(s); calc_dp(s, dp[0]); reverse(a + 1, a + 1 + k); reverse(s.begin(), s.end()); calc(s); calc_dp(s, dp[1]); reverse(dp[1], dp[1] + k + 2); reverse(a + 1, a + 1 + k); reverse(s.begin(), s.end()); calc(s); 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][min(n + 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...