Submission #752736

# Submission time Handle Problem Language Result Execution time Memory
752736 2023-06-03T14:19:37 Z benjaminkleyn Painting Walls (APIO20_paint) C++17
0 / 100
10 ms 468 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
typedef bitset<50000> mask;

mask v[100000];
int lg[100001];

bool query(int l, int r, vector<vector<mask>> &raq)
{
    int t = lg[r - l + 1];
    return (raq[t][l] & raq[t][r - (1 << t) + 1]).count() > 0;
}

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
    lg[1] = 0;
    for (int x = 2; x <= N; x++)
        lg[x] = 1 + lg[x/2];
    for (int i = 0; i < M; i++)
        for (int c : B[i])
            v[c][i] = 1;

    mask ones;
    for (int i = 0; i < M; i++) ones[i] = 1;

    vector<vector<mask>> raq(lg[N] + 1, vector<mask>(N));
    for (int i = 0; i < N; i++)
        raq[0][i] = ((v[C[i]] >> (i % M)) | (v[C[i]] << ((100 * M - i) % M))) & ones;

    for (int t = 1; (1 << t) <= N; t++)
        for (int i = 0; i + (1 << t) - 1 < N; i++)
            raq[t][i] = raq[t-1][i] & raq[t-1][i + (1 << (t-1))];

    int ans = 0;
    for (int i = 0, j; i < N; i = j)
    {
        mask cur = raq[0][i];
        j = i + 1;
        for (int t = lg[N]; t >= 0; t--)
            if (j + (1 << t) - 1 < N && (cur & raq[t][j]).count() > 0)
                j += (1 << t), cur &= raq[t][j];

        j = min(j, i + M);
        if (!query(j-M, j-1, raq))
            return -1;
        ans++;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Runtime error 10 ms 468 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Runtime error 10 ms 468 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Runtime error 10 ms 468 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Runtime error 10 ms 468 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Runtime error 10 ms 468 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -