Submission #1270841

#TimeUsernameProblemLanguageResultExecution timeMemory
1270841BlockOGPaint By Numbers (IOI16_paint)C++20
32 / 100
0 ms328 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! https://vividstasis.gay

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

int n;
vector<int> c;

int empties[200001];
bool check_empty(int l, int r) {
    return empties[min(r, n)] - empties[l];
}

int filled[200001];
bool check_filled(int l, int r) {
    return filled[min(r, n)] - filled[l];
}

int bit_empties[200001];
int get_empty(int i) {
    int res = 0;
    for (i++; i > 0; i -= i & -i) res += bit_empties[i];
    return res;
}
void add_empty(int i, int v) {
    for (i++; i <= 200000; i += i & -i) bit_empties[i] += v;
}

int bit_filled[200001];
int get_filled(int i) {
    int res = 0;
    for (i++; i > 0; i -= i & -i) res += bit_filled[i];
    return res;
}
void add_filled(int i, int v) {
    for (i++; i <= 200000; i += i & -i) bit_filled[i] += v;
}

int checked[101];

int check(int i, int j) {
    if (i >= c.size()) return 1;
    checked[i] = j;

    if (check_empty(j, j + c[i])) return 0;

    int valids = 0;
    of(k, j + c[i] + 1, checked[i + 1]) {
        if (!check_filled(j + c[i], k)) {
            int did = check(i + 1, k);

            add_empty(j + c[i], did);
            add_empty(k, -did);

            valids += did;
        }
    }

    add_filled(j, valids);
    add_filled(j + c[i], -valids);

    return valids;
}

string solve_puzzle(string s, vector<int> _c) {
    n = s.size();
    c = _c;

    fo(i, 0, c.size()) checked[i] = n - c[i] + 1;
    checked[c.size()] = n + 2;

    fo(i, 0, n) {
        empties[i + 1] = empties[i] + (s[i] == '_');
        filled[i + 1] = filled[i] + (s[i] == 'X');
    }

    of(i, 0, checked[0]) if (!check_filled(0, i)) {
        int did = check(0, i);
        add_empty(0, did);
        add_empty(i, -did);
    }

    string res(n, '?');
    fo(i, 0, n) {
        if (get_empty(i) == 0) res[i] = 'X';
        else if (get_filled(i) == 0) res[i] = '_';
    }

    return res;
}

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...