Submission #850122

# Submission time Handle Problem Language Result Execution time Memory
850122 2023-09-15T19:04:22 Z tvladm2009 Painting Walls (APIO20_paint) C++17
0 / 100
0 ms 344 KB
#include "paint.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m, k;

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
        vector<int> a, c;
        vector<vector<int>> b;

        n = N;
        m = M;
        k = K;
        c = C;
        a = A;
        b = B;
        assert((int)c.size() == n);
        assert((int)a.size() == m);
        assert((int)b.size() == m);
        for (int i = 0; i < m; i++) {
                assert((int)b[i].size() == a[i]);
        }

        vector<int> f(k, 0);
        for (int i = 0; i < m; i++) {
                for (auto& it : b[i]) {
                        f[it]++;
                }
        }
        vector<int> has(k, -1);
        vector<int> need(n, 0);
        for (int i = 0; i < m; i++) {
                for (auto& it : b[i]) {
                        has[it] = i;
                }
        }
        for (int i = 0; i < n; i++) {
                if (f[c[i]] == 0) {
                        return -1;
                }
                need[i] = has[c[i]];
        }
        int sol = 0, pos = c[0], cur = 0;
        for (int i = 1; i < n; i++) {
                bool ok = false;
                ok |= (need[i] == (pos + 1) % m);

                if (!ok) {
                        if (cur < m) {
                                return -1;
                        }
                        sol += (cur + m - 1) / m;
                        cur = 0;
                }
                cur++;
                pos = need[i];
        }
        if (cur < m) {
                return -1;
        }
        sol += (cur + m - 1) / m;
        return sol;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -