Submission #850127

# Submission time Handle Problem Language Result Execution time Memory
850127 2023-09-15T19:20:16 Z tvladm2009 Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 600 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(n, 0);
        for (int i = 0; i < m; i++) {
                for (auto& it : b[i]) {
                        f[it]++;
                }
        }
        bool subtask1 = 1;
        for (int i = 0; i < k; i++) {
                if (f[i] > 1) {
                        subtask1 = 0;
                }
        }
        
        if (subtask1) {
                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 = need[0], cur = 1;
                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;
        }
 
 
        vector<bool> isok(n * m, 0), ok(n, 0);
        vector<int> best(n * m, 0);
 
        vector<bool> act(k, 0);
 
        for (int w = 0; w < m; w++) {
                for (auto& col : b[w]) {
                        act[col] = 1;
                }
                for (int i = 0; i < n; i++) {
                        if (act[c[i]]) {
                                isok[i * m + w] = 1;
                        }
                }
                for (auto& col : b[w]) {
                        act[col] = 0;
                }
        }
 
        for (int i = n - 1; i >= 0; i--) {
                for (int w = 0; w < m; w++) {
                        if (isok[i * m + w]) {
                                best[i * m + w] = 1;
                                if (i + 1 < n) {
                                        best[i * m + w] += best[(i + 1) * m + (w + 1) % m];
                                }
                        }
                }
        }
 
        for (int y = 0; y + m - 1 < n; y++) {
                for (int w = 0; w < m; w++) {
                        if (best[y * m + w] >= m) {
                                ok[y] = 1;
                        }
                }
        }
 
        vector<int> inds;
        for (int i = 0; i < n; i++) {
                if (ok[i]) {
                        inds.push_back(i);
                }
        }
        if (inds.empty()) {
                return -1;
        }
        assert((int) inds.size() >= 1);
        if (inds[0] != 0 || inds.back() != n - m) {
                return -1;
        }
        int l = 0, cost = 0;
        while (1) {
                int r = l;
                cost++;
                while (r + 1 < (int) inds.size() && inds[r + 1] <= inds[l] + m) {
                        r++;
                }
                if (r == (int) inds.size() - 1) {
                        if (l < r) {
                                cost++;
                        }
                        break;
                }
                if (l == r) {
                        return -1;
                }
                l = r;
        }
        return cost;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Runtime error 1 ms 600 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Runtime error 1 ms 600 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Runtime error 1 ms 600 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Runtime error 1 ms 600 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Runtime error 1 ms 600 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -