Submission #811282

#TimeUsernameProblemLanguageResultExecution timeMemory
811282becaidoPaint By Numbers (IOI16_paint)C++17
100 / 100
221 ms13672 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "paint.h" #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 2e5 + 5; const int MAX = 105; int n, k; string ans; int pre[SIZE], x[SIZE], y[SIZE]; bitset<SIZE> L[2][MAX], R[2][MAX]; string solve_puzzle(string s, vector<int> c) { n = s.size(); k = c.size(); ans.resize(n, '?'); FOR (i, 0, n - 1) pre[i] = (i ? pre[i - 1] : 0) + (s[i] == '_'); auto sum = [&](int l, int r) { return pre[r] - (l ? pre[l - 1] : 0); }; FOR (i, 0, k) FOR (j, 0, n - 1) { if (s[j] != 'X') L[0][i][j] = (i == 0 || j > 0) && (j == 0 || L[0][i][j - 1] || L[1][i][j - 1]); if (i > 0 && j >= c[i - 1] - 1 && sum(j - c[i - 1] + 1, j) == 0) L[1][i][j] = (i == 1 && j == c[i - 1] - 1) || (j >= c[i - 1] && L[0][i - 1][j - c[i - 1]]); } for (int i = k + 1; i >= 1; i--) for (int j = n - 1; j >= 0; j--) { if (s[j] != 'X') R[0][i][j] = (i == k + 1 || j < n - 1) && (j == n - 1 || R[0][i][j + 1] || R[1][i][j + 1]); if (i <= k && j + c[i - 1] <= n && sum(j, j + c[i - 1] - 1) == 0) R[1][i][j] = (i == k && j + c[i - 1] == n) || (j + c[i - 1] < n && R[0][i + 1][j + c[i - 1]]); } FOR (i, 0, k) FOR (j, 0, n - 1) { if (i >= 1 && L[1][i][j] && ((i == k && j == n - 1) || (j < n - 1 && R[0][i + 1][j + 1]))) { x[j - c[i - 1] + 1]++; x[j + 1]--; } if (L[0][i][j] && R[0][i + 1][j]) y[j] = 1; } FOR (i, 0, n - 1) { if (!x[i]) ans[i] = '_'; if (!y[i]) ans[i] = 'X'; x[i + 1] += x[i]; } return ans; } /* in1 .......... 2 3 4 out1 ??X???XX?? in2 ........ 2 3 4 out2 XXX_XXXX in3 ..._._.... 1 3 out3 ???___???? in4 .X........ 1 3 out4 ?XX?______ */ #ifdef WAIMAI const int S_MAX_LEN = 200 * 1000; char buf[S_MAX_LEN + 1]; int main() { assert(1 == scanf("%s", buf)); string s = buf; int c_len; assert(1 == scanf("%d", &c_len)); vector<int> c(c_len); for (int i = 0; i < c_len; i++) { assert(1 == scanf("%d", &c[i - 1])); } string ans = solve_puzzle(s, c); printf("%s\n", ans.data()); return 0; } #endif
#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...