Submission #1246656

#TimeUsernameProblemLanguageResultExecution timeMemory
1246656LemserPaint By Numbers (IOI16_paint)C++20
100 / 100
554 ms85028 KiB
#include "paint.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #pragma GCC target("popcnt") using namespace std; using ll = long long; using ull = unsigned long long; using lld = long double; using ii = pair<int,int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; using vpll = vector<pll>; using vlld = vector<lld>; #define all(x) x.begin(),x.end() #define lsb(x) x&(-x) #define gcd(a,b) __gcd(a,b) #define sz(x) (int)x.size() #define mp make_pair #define pb push_back #define fi first #define se second #define fls cout.flush() #define fore(i, l, r) for (auto i = l; i < r; i++) #define fo(i, n) fore (i, 0, n) #define forex(i, r, l) for (auto i = r-1; i >= l; i--) #define ffo(i, n) forex (i, n, 0) bool cmin(ll &a, ll b) { if (b < a) { a=b; return 1; } return 0; } bool cmax(ll &a, ll b) { if (b > a) { a=b; return 1; } return 0; } const int INF = 1e9 + 7; const int N = 2e5 + 3, K = 103; bool dppref[N][K][2], dpsuf[N][K][2]; void prec (ll n, ll k, string s, vector<int> &c, vector<int> &pf) { s = 'w' + s + 'w'; {auto d = c; c = vector<int>(1, 0); fo (i, k) c.pb(d[i]);} fore (i, 1, n+1) pf[i] = pf[i-1] + (s[i] == '_'); dppref[0][0][0] = 1; dppref[0][0][1] = 1; fore (i, 1, n+1) { fo (j, k+1) { // elegir nada dppref[i][j][0] = ((dppref[i-1][j][0] || dppref[i-1][j][1]) && (s[i] != 'X' ? 1 : 0)); // elegir substring if (c[j] <= i && j > 0) { bool ok = (pf[i] - pf[i-c[j]] == 0 ? 1 : 0); ok &= (s[i-c[j]] != 'X'); if (c[j] == i) dppref[i][j][1] = ((j == 1) && ok); else dppref[i][j][1] = (dppref[i-c[j]][j-1][0] && ok); } } } dpsuf[n+1][0][0] = 1; dpsuf[n+1][0][1] = 1; forex (i, n+1, 1) { fo (j, k+1) { // elegir nada dpsuf[i][j][0] = ((dpsuf[i+1][j][0] || dpsuf[i+1][j][1]) && (s[i] != 'X' ? 1 : 0)); // elegir substring if (c[k-j+1] <= n - i + 1 && j > 0) { bool ok = (pf[i+c[k-j+1]-1] - pf[i-1] == 0 ? 1 : 0); ok &= (s[i+c[k-j+1]] != 'X'); if (c[k-j+1] == n - i + 1) dpsuf[i][j][1] = ((j == 1) && ok); else dpsuf[i][j][1] = (dpsuf[i+c[k-j+1]][j-1][0] && ok); } } } } string solve_puzzle(string s, vector<int> c) { ll n = s.size(), k = c.size(); string ans = s; vector<int> pf(n+3, 0ll), func(n+3, 0), X(n+3, 0), Y(n+3, 0); prec(n, k, s, c, pf); fore (j, 1, k+1) { fore (i, 1, n+1) { func[i] = ((dppref[i][j][1] && dpsuf[i+1][k-j][0])); func[i] += func[i-1]; } fo (i, n) { if (s[i] != '.') continue; X[i] |= (func[min(ll(i+c[j]), n)] > func[i] ? 1 : 0); Y[i] |= (dppref[i+1][j][0] && (dpsuf[i+2][k-j][0] || dpsuf[i+2][k-j][1])); Y[i] |= (dppref[i+1][0][0] && (dpsuf[i+2][k][0] || dpsuf[i+2][k][1])); } } fo (i, n) { if (s[i] != '.') continue; ans[i] = ((X[i] && Y[i]) ? '?' : (X[i] ? 'X' : '_')); } return ans; }

Compilation message (stderr)

paint.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
paint_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...