Submission #811268

#TimeUsernameProblemLanguageResultExecution timeMemory
811268becaidoPaint By Numbers (IOI16_paint)C++17
100 / 100
231 ms13680 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 #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #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 /* r[i] = l[i] + c[i] r[i] < l[i + 1] 0 <= l[0] r[k - 1] <= n */ 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(); c.insert(c.begin(), 0); 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 && sum(j - c[i] + 1, j) == 0) L[1][i][j] = (i == 1 && j == c[i] - 1) || (j >= c[i] && L[0][i - 1][j - c[i]]); } 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] <= n && sum(j, j + c[i] - 1) == 0) R[1][i][j] = (i == k && j + c[i] == n) || (j + c[i] < n && R[0][i + 1][j + c[i]]); } 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]++; 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])); } 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...