Submission #738495

# Submission time Handle Problem Language Result Execution time Memory
738495 2023-05-08T20:52:36 Z colossal_pepe Painting Walls (APIO20_paint) C++17
12 / 100
57 ms 22480 KB
#include "paint.h"

#include <iostream>
#include <vector>
using namespace std;

int n, m, k;
vector<int> c, a;
vector<vector<int>> b;

vector<vector<int>> getLikedBy() {
    vector<vector<int>> ret(k);
    for (int i = 0; i < m; i++) {
        for (int j : b[i]) {
            ret[j].push_back(i);
        }
    }
    return ret;
}

int val(int i, int j, vector<vector<int>> &dp) {
    return (i < n ? dp[i][j] : 0);
}

int solve(vector<vector<int>> &liked_by) {
    // cout << "TF IS HAPPENING" << endl;
    vector<vector<int>> dp(n);
    for (int i = 0; i < n; i++) {
        if (liked_by[c[i]].empty()) return -1;
        dp[i].resize(i ? liked_by[c[i - 1]].size() + 1 : 1, 0);
    }
    if (n == 1) return 1;
    // cout << "EIKHANE ASCHE?" << endl;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < liked_by[c[i]].size(); j++) {
            dp[i].back() = max(dp[i].back(), 1 + val(i + 1, j, dp));
        }
        if (i == 0) continue;
        int j_cur = 0, j_prv;
        for (j_prv = 0; j_prv < liked_by[c[i - 1]].size(); j_prv++) {
            while (j_cur < liked_by[c[i]].size() and liked_by[c[i]][j_cur] <= liked_by[c[i - 1]][j_prv]) j_cur++;
            if (j_cur < liked_by[c[i]].size() and liked_by[c[i]][j_cur] == liked_by[c[i - 1]][j_prv] + 1) dp[i][j_prv] = 1 + val(i + 1, j_cur, dp);
        }
        if (liked_by[c[i]].front() == 0 and liked_by[c[i - 1]].back() == m - 1) dp[i][liked_by[c[i - 1]].size() - 1] = 1 + val(i + 1, 0, dp);
    }
    int ret = 0, start_at = (dp[0].back() >= m ? 0 : -1), needs_colour = 0;
    for (int i = 0; i < n; i++) {
        if (i == needs_colour) {
            if (start_at == -1) return -1;
            ret++;
            start_at = -1;
            needs_colour = i + m;
        }
        if (dp[i].back() >= m) start_at = i;
    }
    return ret;
}

int minimumInstructions(
    int N, int M, int K, vector<int> C,
    vector<int> A, vector<vector<int>> B) {
    n = N, m = M, k = K;
    c = C, a = A;
    b = B;
    vector<vector<int>> liked_by = getLikedBy();
    return solve(liked_by);
}

Compilation message

paint.cpp: In function 'int solve(std::vector<std::vector<int> >&)':
paint.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j = 0; j < liked_by[c[i]].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (j_prv = 0; j_prv < liked_by[c[i - 1]].size(); j_prv++) {
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |             while (j_cur < liked_by[c[i]].size() and liked_by[c[i]][j_cur] <= liked_by[c[i - 1]][j_prv]) j_cur++;
      |                    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if (j_cur < liked_by[c[i]].size() and liked_by[c[i]][j_cur] == liked_by[c[i - 1]][j_prv] + 1) dp[i][j_prv] = 1 + val(i + 1, j_cur, dp);
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 2 ms 2732 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2736 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 19 ms 7476 KB Output is correct
23 Correct 21 ms 7516 KB Output is correct
24 Correct 17 ms 7508 KB Output is correct
25 Correct 3 ms 1620 KB Output is correct
26 Correct 3 ms 1592 KB Output is correct
27 Correct 3 ms 1564 KB Output is correct
28 Correct 4 ms 1592 KB Output is correct
29 Correct 4 ms 1620 KB Output is correct
30 Correct 3 ms 1620 KB Output is correct
31 Correct 9 ms 5176 KB Output is correct
32 Correct 9 ms 5172 KB Output is correct
33 Correct 9 ms 5224 KB Output is correct
34 Correct 9 ms 5272 KB Output is correct
35 Correct 13 ms 5244 KB Output is correct
36 Correct 10 ms 5204 KB Output is correct
37 Correct 26 ms 9116 KB Output is correct
38 Correct 23 ms 9172 KB Output is correct
39 Correct 33 ms 9160 KB Output is correct
40 Correct 13 ms 6452 KB Output is correct
41 Correct 9 ms 4156 KB Output is correct
42 Correct 15 ms 7076 KB Output is correct
43 Correct 10 ms 4664 KB Output is correct
44 Correct 9 ms 4308 KB Output is correct
45 Correct 16 ms 7040 KB Output is correct
46 Correct 47 ms 20684 KB Output is correct
47 Correct 28 ms 12800 KB Output is correct
48 Correct 33 ms 16468 KB Output is correct
49 Correct 44 ms 16668 KB Output is correct
50 Correct 43 ms 16668 KB Output is correct
51 Correct 36 ms 13388 KB Output is correct
52 Correct 14 ms 7128 KB Output is correct
53 Correct 14 ms 7044 KB Output is correct
54 Correct 16 ms 7124 KB Output is correct
55 Correct 15 ms 7124 KB Output is correct
56 Correct 16 ms 7088 KB Output is correct
57 Correct 19 ms 7124 KB Output is correct
58 Correct 52 ms 22476 KB Output is correct
59 Correct 54 ms 22392 KB Output is correct
60 Correct 56 ms 22420 KB Output is correct
61 Correct 52 ms 22448 KB Output is correct
62 Correct 55 ms 22476 KB Output is correct
63 Correct 57 ms 22480 KB Output is correct
64 Correct 55 ms 21240 KB Output is correct
65 Correct 52 ms 21276 KB Output is correct
66 Correct 53 ms 21280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 2 ms 2732 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2736 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 292 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 1876 KB Output is correct
35 Correct 1 ms 1620 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 1 ms 2220 KB Output is correct
38 Correct 2 ms 2352 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 2132 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 2516 KB Output is correct
43 Incorrect 2 ms 2516 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 2732 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2736 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 19 ms 7476 KB Output is correct
25 Correct 21 ms 7516 KB Output is correct
26 Correct 17 ms 7508 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 292 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 296 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 2260 KB Output is correct
37 Correct 1 ms 1876 KB Output is correct
38 Correct 1 ms 1620 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 1 ms 2220 KB Output is correct
41 Correct 2 ms 2352 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 2132 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 2516 KB Output is correct
46 Incorrect 2 ms 2516 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 2732 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2736 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 19 ms 7476 KB Output is correct
25 Correct 21 ms 7516 KB Output is correct
26 Correct 17 ms 7508 KB Output is correct
27 Correct 3 ms 1620 KB Output is correct
28 Correct 3 ms 1592 KB Output is correct
29 Correct 3 ms 1564 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
31 Correct 4 ms 1620 KB Output is correct
32 Correct 3 ms 1620 KB Output is correct
33 Correct 9 ms 5176 KB Output is correct
34 Correct 9 ms 5172 KB Output is correct
35 Correct 9 ms 5224 KB Output is correct
36 Correct 9 ms 5272 KB Output is correct
37 Correct 13 ms 5244 KB Output is correct
38 Correct 10 ms 5204 KB Output is correct
39 Correct 26 ms 9116 KB Output is correct
40 Correct 23 ms 9172 KB Output is correct
41 Correct 33 ms 9160 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 292 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 2260 KB Output is correct
52 Correct 1 ms 1876 KB Output is correct
53 Correct 1 ms 1620 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 1 ms 2220 KB Output is correct
56 Correct 2 ms 2352 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 2132 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 2516 KB Output is correct
61 Incorrect 2 ms 2516 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 2 ms 2732 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2736 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 19 ms 7476 KB Output is correct
25 Correct 21 ms 7516 KB Output is correct
26 Correct 17 ms 7508 KB Output is correct
27 Correct 3 ms 1620 KB Output is correct
28 Correct 3 ms 1592 KB Output is correct
29 Correct 3 ms 1564 KB Output is correct
30 Correct 4 ms 1592 KB Output is correct
31 Correct 4 ms 1620 KB Output is correct
32 Correct 3 ms 1620 KB Output is correct
33 Correct 9 ms 5176 KB Output is correct
34 Correct 9 ms 5172 KB Output is correct
35 Correct 9 ms 5224 KB Output is correct
36 Correct 9 ms 5272 KB Output is correct
37 Correct 13 ms 5244 KB Output is correct
38 Correct 10 ms 5204 KB Output is correct
39 Correct 26 ms 9116 KB Output is correct
40 Correct 23 ms 9172 KB Output is correct
41 Correct 33 ms 9160 KB Output is correct
42 Correct 13 ms 6452 KB Output is correct
43 Correct 9 ms 4156 KB Output is correct
44 Correct 15 ms 7076 KB Output is correct
45 Correct 10 ms 4664 KB Output is correct
46 Correct 9 ms 4308 KB Output is correct
47 Correct 16 ms 7040 KB Output is correct
48 Correct 47 ms 20684 KB Output is correct
49 Correct 28 ms 12800 KB Output is correct
50 Correct 33 ms 16468 KB Output is correct
51 Correct 44 ms 16668 KB Output is correct
52 Correct 43 ms 16668 KB Output is correct
53 Correct 36 ms 13388 KB Output is correct
54 Correct 14 ms 7128 KB Output is correct
55 Correct 14 ms 7044 KB Output is correct
56 Correct 16 ms 7124 KB Output is correct
57 Correct 15 ms 7124 KB Output is correct
58 Correct 16 ms 7088 KB Output is correct
59 Correct 19 ms 7124 KB Output is correct
60 Correct 52 ms 22476 KB Output is correct
61 Correct 54 ms 22392 KB Output is correct
62 Correct 56 ms 22420 KB Output is correct
63 Correct 52 ms 22448 KB Output is correct
64 Correct 55 ms 22476 KB Output is correct
65 Correct 57 ms 22480 KB Output is correct
66 Correct 55 ms 21240 KB Output is correct
67 Correct 52 ms 21276 KB Output is correct
68 Correct 53 ms 21280 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 292 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 296 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 2 ms 2260 KB Output is correct
79 Correct 1 ms 1876 KB Output is correct
80 Correct 1 ms 1620 KB Output is correct
81 Correct 2 ms 2644 KB Output is correct
82 Correct 1 ms 2220 KB Output is correct
83 Correct 2 ms 2352 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 1 ms 2132 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 2 ms 2516 KB Output is correct
88 Incorrect 2 ms 2516 KB Output isn't correct
89 Halted 0 ms 0 KB -