Submission #752709

# Submission time Handle Problem Language Result Execution time Memory
752709 2023-06-03T13:13:48 Z benjaminkleyn Painting Walls (APIO20_paint) C++17
0 / 100
1500 ms 212 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
    vector<set<int>> contractors(K);
    for (int i = 0; i < M; i++)
        for (int c : B[i])
            contractors[c].insert(i);

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans++;
        int R = -1;
        set<int> yay = contractors[C[i]], last;

        for (int l = 0; l < M; l++)
        {
            set<int> baddies;
            last = yay;
            for (int contractor : yay)
                if (contractors[C[i+l]].find((contractor + l) % M) == contractors[C[i+l]].end())
                    baddies.insert(contractor);
            for (int baddy : baddies)
                yay.erase(baddy);
            if (yay.size() == 0)
            {
                R = i + l - 1;
                break;
            }
        }
        if (R == -1)
        {
            R = i + M - 1;
            i = R;
            continue;
        }

        int L = N;
        yay = last;
        int remaining = M - (R - i + 1);
        if (i < remaining)
            return -1;

        for (int l = -1; -l <= -remaining; l--)
        {
            set<int> baddies;
            last = yay;
            for (int contractor : yay)
                if (contractors[C[i+l]].find((M + contractor + l) % M) == contractors[C[i+l]].end())
                    baddies.insert(contractor);
            for (int baddy : baddies)
                yay.erase(baddy);
            if (yay.size() == 0)
            {
                L = i + l + 1;
                break;
            }
        }
        if (L == N)
        {
            L = i - remaining;
            i = R;
            continue;
        }

        return -1;
    }
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1579 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1579 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1579 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1579 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1579 ms 212 KB Time limit exceeded
4 Halted 0 ms 0 KB -