Submission #287513

#TimeUsernameProblemLanguageResultExecution timeMemory
287513Shafin666Paint By Numbers (IOI16_paint)C++14
100 / 100
646 ms321212 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define pb push_back #define pii pair<ll, ll> #define nyan "(=^・ω・^=)" #define read_input freopen("in.txt","r", stdin) #define print_output freopen("out.txt","w", stdout) typedef long long ll; typedef long double ld; using namespace std; const int maxn = 2e5+10, maxk = 103; int n, k; int dp1[maxk][maxn], dp2[maxk][maxn]; int dash[maxn], crs[maxn]; int p1[maxk][maxn], p2[maxk][maxn]; string str; int x[maxn], y[maxn]; bool okx(int l, int r) { if(l >= 2 && str[l-2] == 'X') return 0; if(r < n && str[r] == 'X') return 0; return (dash[r] - dash[l-1] == 0); } std::string solve_puzzle(std::string s, std::vector<int> c) { n = s.length(); str = s; k = c.size(); for(int i = 1; i <= n; i++) { dash[i] = dash[i-1] + (str[i-1] == '_'); crs[i] = crs[i-1] + (str[i-1] == 'X'); } dp1[0][0] = 1; p1[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) p1[0][i] = 1; for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) { int f1 = p1[j][i-1], f2; if(i < c[j-1]) f2 = 0; else if(j > 1) f2 = p1[j-1][i - c[j-1] - 1] & okx(i - c[j-1] + 1, i); else f2 = p1[j-1][i - c[j-1]] & okx(i - c[j-1] + 1, i); if(str[i-1] == '_') p1[j][i] = f1; else if(str[i-1] == 'X') p1[j][i] = f2; else p1[j][i] = f1 | f2; dp1[j][i] = f2; dp1[0][i] = p1[0][i]; } } reverse(str.begin(), str.end()); reverse(c.begin(), c.end()); for(int i = 1; i <= n; i++) { dash[i] = dash[i-1] + (str[i-1] == '_'); crs[i] = crs[i-1] + (str[i-1] == 'X'); } dp2[0][0] = 1; p2[0][0] = 1; for(int i = 1; i <= n && str[i-1] != 'X'; i++) p2[0][i] = 1; for(int j = 1; j <= k; j++) { for(int i = 1; i <= n; i++) { int f1 = p2[j][i-1], f2; if(i < c[j-1]) f2 = 0; else if(j > 1) f2 = p2[j-1][i - c[j-1] - 1] & okx(i - c[j-1] + 1, i); else f2 = p2[j-1][i - c[j-1]] & okx(i - c[j-1] + 1, i); if(str[i-1] == '_') p2[j][i] = f1; else if(str[i-1] == 'X') p2[j][i] = f2; else p2[j][i] = f1 | f2; dp2[j][i] = f2; dp2[0][i] = p2[0][i]; } } for(int j = 0; j <= k; j++) { for(int i = 1; 2 * i <= n; i++) { swap(dp2[j][i], dp2[j][n-i+1]); swap(p2[j][i], p2[j][n-i+1]); } } p2[0][n+1] = p2[0][n+2] = 1; dp2[0][n+1] = 1; reverse(c.begin(), c.end()); for(int i = 1; i <= n; i++) { if(s[i-1] == '_') continue; for(int j = 1; j <= k; j++) { if(dp1[j][i] & p2[k-j][i+2]) { x[i+1]--; x[i - c[j-1] + 1]++; } } } for(int i = 1; i <= n; i++) { if(s[i-1] == 'X') continue; for(int j = 0; j <= k; j++) { y[i] = max(y[i], p1[j][i-1] & p2[k-j][i+1]); } } for(int i = 1; i <= n; i++) x[i] += x[i-1]; for(int i = 1; i <= n; i++) x[i] = (x[i] > 0); string res = ""; for(int i = 1; i <= n; i++) { if(s[i-1] == 'X') res.pb('X'); //res += "X"; else if(s[i-1] == '_') res.pb('_'); //res += "_"; else if(x[i] && y[i]) res.pb('?'); //res += "?"; else if(y[i]) res.pb('_'); //res += "_"; else res.pb('X'); //res += "X"; } return res; }

Compilation message (stderr)

paint.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
paint.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#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...