Submission #788607

# Submission time Handle Problem Language Result Execution time Memory
788607 2023-07-20T12:09:08 Z mindiyak Painting Walls (APIO20_paint) C++14
28 / 100
1500 ms 47876 KB
#include "paint.h"

#include <vector>
#include <unordered_set>
// #include <iostream>

using namespace std;

vector<int> dp(1000000,1e9);
vector<vector<int>> colors(1000000,vector<int>()); 

int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
  vector<unordered_set<int>> contrcatorColor(M,unordered_set<int>());

  bool case1 = true;
  for(int i=0;i<M;i++){
    for(int j=0;j<A[i];j++){
      colors[B[i][j]].push_back(i);
      contrcatorColor[i].insert(B[i][j]);
      if(colors[B[i][j]].size() > 1){
        case1 = false;
      }
    }
  }

  bool possible = true;
  for(int i=0;i<=(N-M);i++){
    // cout << "start pos is " << i << endl;
    bool coloured = false;
    for(int j=0;j<(int)colors[C[i]].size();j++){
      int contractorStart = colors[C[i]][j];
      possible = true;
      // cout << "contractor start " << contractorStart << endl;
      for(int k=0;k<M;k++){
        // cout << (contractorStart+k)%M << " contractor " << C[i+k] << " color " << contrcatorColor[(contractorStart+k)%M].count(C[i+k]) << endl;
        if(contrcatorColor[(contractorStart+k)%M].count(C[i+k]) == 0){
          possible = false;
          break;
        }
      }
      if(possible){
        // cout << "possible to paint " << i << " start from " << contractorStart << endl; 
        coloured = true;
        break;
      }
    }
    
    if(coloured){
      if(i==0){
        dp[(M-1+i)] = 1;
      }else{
        dp[(M-1+i)] = dp[i-1]+1;
      }
      for(int k=i;k<(M+i);k++){
        dp[(M-1+i)] = min(dp[(M-1+i)],dp[k]+1);
      }
      
      // cout << " pos-" << (M-1+i) << " dp[M-1]-" << dp[(M-1+i)] << endl;
    }else{
      if(case1){
        return -1;
      }
    }
    // cout << endl;
  }

  // for(int i=0;i<N;i++){
  //   cout << dp[i] << " ";
  // }cout << endl;

  if(dp[N-1] >= 1e9){
    return -1;
  }
  return dp[N-1];
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27604 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Correct 15 ms 27612 KB Output is correct
4 Correct 15 ms 27700 KB Output is correct
5 Correct 15 ms 27632 KB Output is correct
6 Correct 15 ms 27588 KB Output is correct
7 Correct 15 ms 27604 KB Output is correct
8 Correct 15 ms 27604 KB Output is correct
9 Correct 16 ms 27680 KB Output is correct
10 Correct 16 ms 27700 KB Output is correct
11 Correct 15 ms 27700 KB Output is correct
12 Correct 15 ms 27604 KB Output is correct
13 Correct 17 ms 27704 KB Output is correct
14 Correct 17 ms 27696 KB Output is correct
15 Correct 20 ms 27724 KB Output is correct
16 Correct 20 ms 27704 KB Output is correct
17 Correct 16 ms 27708 KB Output is correct
18 Correct 16 ms 27736 KB Output is correct
19 Correct 16 ms 27800 KB Output is correct
20 Correct 16 ms 27808 KB Output is correct
21 Correct 16 ms 27740 KB Output is correct
22 Correct 37 ms 36152 KB Output is correct
23 Correct 36 ms 36120 KB Output is correct
24 Correct 36 ms 36172 KB Output is correct
25 Correct 16 ms 27840 KB Output is correct
26 Correct 17 ms 27876 KB Output is correct
27 Correct 17 ms 27848 KB Output is correct
28 Correct 16 ms 27860 KB Output is correct
29 Correct 17 ms 27816 KB Output is correct
30 Correct 17 ms 27840 KB Output is correct
31 Correct 772 ms 29952 KB Output is correct
32 Correct 781 ms 29948 KB Output is correct
33 Correct 784 ms 29952 KB Output is correct
34 Correct 781 ms 29952 KB Output is correct
35 Correct 808 ms 29952 KB Output is correct
36 Correct 804 ms 29948 KB Output is correct
37 Correct 41 ms 36836 KB Output is correct
38 Correct 40 ms 36848 KB Output is correct
39 Correct 40 ms 36884 KB Output is correct
40 Correct 26 ms 28480 KB Output is correct
41 Correct 20 ms 28232 KB Output is correct
42 Correct 21 ms 28628 KB Output is correct
43 Correct 19 ms 28224 KB Output is correct
44 Correct 18 ms 28244 KB Output is correct
45 Correct 21 ms 28664 KB Output is correct
46 Execution timed out 1574 ms 47876 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27604 KB Output is correct
2 Correct 18 ms 27604 KB Output is correct
3 Correct 15 ms 27612 KB Output is correct
4 Correct 15 ms 27700 KB Output is correct
5 Correct 15 ms 27632 KB Output is correct
6 Correct 15 ms 27588 KB Output is correct
7 Correct 15 ms 27604 KB Output is correct
8 Correct 15 ms 27604 KB Output is correct
9 Correct 16 ms 27680 KB Output is correct
10 Correct 16 ms 27700 KB Output is correct
11 Correct 15 ms 27700 KB Output is correct
12 Correct 15 ms 27604 KB Output is correct
13 Correct 17 ms 27704 KB Output is correct
14 Correct 17 ms 27696 KB Output is correct
15 Correct 20 ms 27724 KB Output is correct
16 Correct 20 ms 27704 KB Output is correct
17 Correct 16 ms 27708 KB Output is correct
18 Correct 16 ms 27736 KB Output is correct
19 Correct 16 ms 27800 KB Output is correct
20 Correct 16 ms 27808 KB Output is correct
21 Correct 16 ms 27740 KB Output is correct
22 Correct 18 ms 27696 KB Output is correct
23 Correct 15 ms 27604 KB Output is correct
24 Correct 15 ms 27604 KB Output is correct
25 Correct 14 ms 27700 KB Output is correct
26 Correct 15 ms 27604 KB Output is correct
27 Correct 17 ms 27708 KB Output is correct
28 Correct 16 ms 27792 KB Output is correct
29 Correct 15 ms 27604 KB Output is correct
30 Correct 16 ms 27708 KB Output is correct
31 Correct 14 ms 27604 KB Output is correct
32 Correct 17 ms 27704 KB Output is correct
33 Correct 16 ms 27648 KB Output is correct
34 Correct 16 ms 27732 KB Output is correct
35 Correct 16 ms 27732 KB Output is correct
36 Correct 16 ms 27732 KB Output is correct
37 Correct 19 ms 27772 KB Output is correct
38 Correct 15 ms 27732 KB Output is correct
39 Correct 15 ms 27648 KB Output is correct
40 Correct 16 ms 27780 KB Output is correct
41 Correct 16 ms 27732 KB Output is correct
42 Correct 16 ms 27740 KB Output is correct
43 Correct 15 ms 27732 KB Output is correct
44 Correct 15 ms 27624 KB Output is correct
45 Correct 15 ms 27604 KB Output is correct
46 Correct 16 ms 27620 KB Output is correct
47 Correct 16 ms 27732 KB Output is correct
48 Correct 15 ms 27604 KB Output is correct
49 Correct 15 ms 27724 KB Output is correct
50 Correct 16 ms 27732 KB Output is correct
51 Correct 16 ms 27732 KB Output is correct
52 Correct 17 ms 27728 KB Output is correct
53 Correct 17 ms 27732 KB Output is correct
54 Correct 16 ms 27732 KB Output is correct
55 Correct 17 ms 27772 KB Output is correct
56 Correct 16 ms 27732 KB Output is correct
57 Correct 16 ms 27704 KB Output is correct
58 Correct 16 ms 27732 KB Output is correct
59 Correct 19 ms 27732 KB Output is correct
60 Correct 16 ms 27764 KB Output is correct
61 Correct 16 ms 27712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27696 KB Output is correct
2 Correct 15 ms 27604 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 18 ms 27604 KB Output is correct
5 Correct 15 ms 27612 KB Output is correct
6 Correct 15 ms 27700 KB Output is correct
7 Correct 15 ms 27632 KB Output is correct
8 Correct 15 ms 27588 KB Output is correct
9 Correct 15 ms 27604 KB Output is correct
10 Correct 15 ms 27604 KB Output is correct
11 Correct 16 ms 27680 KB Output is correct
12 Correct 16 ms 27700 KB Output is correct
13 Correct 15 ms 27700 KB Output is correct
14 Correct 15 ms 27604 KB Output is correct
15 Correct 17 ms 27704 KB Output is correct
16 Correct 17 ms 27696 KB Output is correct
17 Correct 20 ms 27724 KB Output is correct
18 Correct 20 ms 27704 KB Output is correct
19 Correct 16 ms 27708 KB Output is correct
20 Correct 16 ms 27736 KB Output is correct
21 Correct 16 ms 27800 KB Output is correct
22 Correct 16 ms 27808 KB Output is correct
23 Correct 16 ms 27740 KB Output is correct
24 Correct 37 ms 36152 KB Output is correct
25 Correct 36 ms 36120 KB Output is correct
26 Correct 36 ms 36172 KB Output is correct
27 Correct 15 ms 27604 KB Output is correct
28 Correct 14 ms 27700 KB Output is correct
29 Correct 15 ms 27604 KB Output is correct
30 Correct 17 ms 27708 KB Output is correct
31 Correct 16 ms 27792 KB Output is correct
32 Correct 15 ms 27604 KB Output is correct
33 Correct 16 ms 27708 KB Output is correct
34 Correct 14 ms 27604 KB Output is correct
35 Correct 17 ms 27704 KB Output is correct
36 Correct 16 ms 27648 KB Output is correct
37 Correct 16 ms 27732 KB Output is correct
38 Correct 16 ms 27732 KB Output is correct
39 Correct 16 ms 27732 KB Output is correct
40 Correct 19 ms 27772 KB Output is correct
41 Correct 15 ms 27732 KB Output is correct
42 Correct 15 ms 27648 KB Output is correct
43 Correct 16 ms 27780 KB Output is correct
44 Correct 16 ms 27732 KB Output is correct
45 Correct 16 ms 27740 KB Output is correct
46 Correct 15 ms 27732 KB Output is correct
47 Correct 15 ms 27624 KB Output is correct
48 Correct 15 ms 27604 KB Output is correct
49 Correct 16 ms 27620 KB Output is correct
50 Correct 16 ms 27732 KB Output is correct
51 Correct 15 ms 27604 KB Output is correct
52 Correct 15 ms 27724 KB Output is correct
53 Correct 16 ms 27732 KB Output is correct
54 Correct 16 ms 27732 KB Output is correct
55 Correct 17 ms 27728 KB Output is correct
56 Correct 17 ms 27732 KB Output is correct
57 Correct 16 ms 27732 KB Output is correct
58 Correct 17 ms 27772 KB Output is correct
59 Correct 16 ms 27732 KB Output is correct
60 Correct 16 ms 27704 KB Output is correct
61 Correct 16 ms 27732 KB Output is correct
62 Correct 19 ms 27732 KB Output is correct
63 Correct 16 ms 27764 KB Output is correct
64 Correct 16 ms 27712 KB Output is correct
65 Correct 17 ms 27672 KB Output is correct
66 Correct 15 ms 27648 KB Output is correct
67 Correct 17 ms 27628 KB Output is correct
68 Correct 17 ms 27664 KB Output is correct
69 Correct 15 ms 27732 KB Output is correct
70 Correct 21 ms 28220 KB Output is correct
71 Correct 20 ms 28372 KB Output is correct
72 Correct 19 ms 28264 KB Output is correct
73 Correct 16 ms 27988 KB Output is correct
74 Correct 18 ms 28244 KB Output is correct
75 Correct 19 ms 28200 KB Output is correct
76 Correct 40 ms 34856 KB Output is correct
77 Correct 40 ms 35584 KB Output is correct
78 Correct 59 ms 37100 KB Output is correct
79 Correct 16 ms 27732 KB Output is correct
80 Correct 17 ms 27732 KB Output is correct
81 Correct 21 ms 27676 KB Output is correct
82 Correct 18 ms 27732 KB Output is correct
83 Correct 17 ms 27688 KB Output is correct
84 Correct 20 ms 28500 KB Output is correct
85 Correct 23 ms 28512 KB Output is correct
86 Correct 22 ms 28500 KB Output is correct
87 Correct 21 ms 28464 KB Output is correct
88 Correct 22 ms 28500 KB Output is correct
89 Correct 22 ms 28476 KB Output is correct
90 Correct 56 ms 37972 KB Output is correct
91 Correct 51 ms 37940 KB Output is correct
92 Correct 61 ms 38140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27696 KB Output is correct
2 Correct 15 ms 27604 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 18 ms 27604 KB Output is correct
5 Correct 15 ms 27612 KB Output is correct
6 Correct 15 ms 27700 KB Output is correct
7 Correct 15 ms 27632 KB Output is correct
8 Correct 15 ms 27588 KB Output is correct
9 Correct 15 ms 27604 KB Output is correct
10 Correct 15 ms 27604 KB Output is correct
11 Correct 16 ms 27680 KB Output is correct
12 Correct 16 ms 27700 KB Output is correct
13 Correct 15 ms 27700 KB Output is correct
14 Correct 15 ms 27604 KB Output is correct
15 Correct 17 ms 27704 KB Output is correct
16 Correct 17 ms 27696 KB Output is correct
17 Correct 20 ms 27724 KB Output is correct
18 Correct 20 ms 27704 KB Output is correct
19 Correct 16 ms 27708 KB Output is correct
20 Correct 16 ms 27736 KB Output is correct
21 Correct 16 ms 27800 KB Output is correct
22 Correct 16 ms 27808 KB Output is correct
23 Correct 16 ms 27740 KB Output is correct
24 Correct 37 ms 36152 KB Output is correct
25 Correct 36 ms 36120 KB Output is correct
26 Correct 36 ms 36172 KB Output is correct
27 Correct 16 ms 27840 KB Output is correct
28 Correct 17 ms 27876 KB Output is correct
29 Correct 17 ms 27848 KB Output is correct
30 Correct 16 ms 27860 KB Output is correct
31 Correct 17 ms 27816 KB Output is correct
32 Correct 17 ms 27840 KB Output is correct
33 Correct 772 ms 29952 KB Output is correct
34 Correct 781 ms 29948 KB Output is correct
35 Correct 784 ms 29952 KB Output is correct
36 Correct 781 ms 29952 KB Output is correct
37 Correct 808 ms 29952 KB Output is correct
38 Correct 804 ms 29948 KB Output is correct
39 Correct 41 ms 36836 KB Output is correct
40 Correct 40 ms 36848 KB Output is correct
41 Correct 40 ms 36884 KB Output is correct
42 Correct 15 ms 27604 KB Output is correct
43 Correct 14 ms 27700 KB Output is correct
44 Correct 15 ms 27604 KB Output is correct
45 Correct 17 ms 27708 KB Output is correct
46 Correct 16 ms 27792 KB Output is correct
47 Correct 15 ms 27604 KB Output is correct
48 Correct 16 ms 27708 KB Output is correct
49 Correct 14 ms 27604 KB Output is correct
50 Correct 17 ms 27704 KB Output is correct
51 Correct 16 ms 27648 KB Output is correct
52 Correct 16 ms 27732 KB Output is correct
53 Correct 16 ms 27732 KB Output is correct
54 Correct 16 ms 27732 KB Output is correct
55 Correct 19 ms 27772 KB Output is correct
56 Correct 15 ms 27732 KB Output is correct
57 Correct 15 ms 27648 KB Output is correct
58 Correct 16 ms 27780 KB Output is correct
59 Correct 16 ms 27732 KB Output is correct
60 Correct 16 ms 27740 KB Output is correct
61 Correct 15 ms 27732 KB Output is correct
62 Correct 15 ms 27624 KB Output is correct
63 Correct 15 ms 27604 KB Output is correct
64 Correct 16 ms 27620 KB Output is correct
65 Correct 16 ms 27732 KB Output is correct
66 Correct 15 ms 27604 KB Output is correct
67 Correct 15 ms 27724 KB Output is correct
68 Correct 16 ms 27732 KB Output is correct
69 Correct 16 ms 27732 KB Output is correct
70 Correct 17 ms 27728 KB Output is correct
71 Correct 17 ms 27732 KB Output is correct
72 Correct 16 ms 27732 KB Output is correct
73 Correct 17 ms 27772 KB Output is correct
74 Correct 16 ms 27732 KB Output is correct
75 Correct 16 ms 27704 KB Output is correct
76 Correct 16 ms 27732 KB Output is correct
77 Correct 19 ms 27732 KB Output is correct
78 Correct 16 ms 27764 KB Output is correct
79 Correct 16 ms 27712 KB Output is correct
80 Correct 17 ms 27672 KB Output is correct
81 Correct 15 ms 27648 KB Output is correct
82 Correct 17 ms 27628 KB Output is correct
83 Correct 17 ms 27664 KB Output is correct
84 Correct 15 ms 27732 KB Output is correct
85 Correct 21 ms 28220 KB Output is correct
86 Correct 20 ms 28372 KB Output is correct
87 Correct 19 ms 28264 KB Output is correct
88 Correct 16 ms 27988 KB Output is correct
89 Correct 18 ms 28244 KB Output is correct
90 Correct 19 ms 28200 KB Output is correct
91 Correct 40 ms 34856 KB Output is correct
92 Correct 40 ms 35584 KB Output is correct
93 Correct 59 ms 37100 KB Output is correct
94 Correct 16 ms 27732 KB Output is correct
95 Correct 17 ms 27732 KB Output is correct
96 Correct 21 ms 27676 KB Output is correct
97 Correct 18 ms 27732 KB Output is correct
98 Correct 17 ms 27688 KB Output is correct
99 Correct 20 ms 28500 KB Output is correct
100 Correct 23 ms 28512 KB Output is correct
101 Correct 22 ms 28500 KB Output is correct
102 Correct 21 ms 28464 KB Output is correct
103 Correct 22 ms 28500 KB Output is correct
104 Correct 22 ms 28476 KB Output is correct
105 Correct 56 ms 37972 KB Output is correct
106 Correct 51 ms 37940 KB Output is correct
107 Correct 61 ms 38140 KB Output is correct
108 Correct 16 ms 27776 KB Output is correct
109 Correct 98 ms 27972 KB Output is correct
110 Correct 228 ms 27988 KB Output is correct
111 Correct 153 ms 27996 KB Output is correct
112 Correct 164 ms 28072 KB Output is correct
113 Correct 91 ms 28080 KB Output is correct
114 Correct 537 ms 30992 KB Output is correct
115 Correct 59 ms 31188 KB Output is correct
116 Correct 409 ms 32004 KB Output is correct
117 Correct 352 ms 31184 KB Output is correct
118 Correct 71 ms 31636 KB Output is correct
119 Correct 729 ms 30644 KB Output is correct
120 Correct 39 ms 33952 KB Output is correct
121 Correct 377 ms 28932 KB Output is correct
122 Correct 43 ms 35148 KB Output is correct
123 Correct 153 ms 28752 KB Output is correct
124 Correct 47 ms 36028 KB Output is correct
125 Correct 80 ms 29036 KB Output is correct
126 Correct 27 ms 29488 KB Output is correct
127 Correct 169 ms 29840 KB Output is correct
128 Correct 53 ms 29268 KB Output is correct
129 Correct 68 ms 29388 KB Output is correct
130 Correct 17 ms 27792 KB Output is correct
131 Correct 136 ms 28036 KB Output is correct
132 Correct 362 ms 28096 KB Output is correct
133 Correct 271 ms 28132 KB Output is correct
134 Correct 212 ms 28140 KB Output is correct
135 Correct 179 ms 28116 KB Output is correct
136 Correct 1499 ms 32828 KB Output is correct
137 Correct 1351 ms 32812 KB Output is correct
138 Execution timed out 1568 ms 32900 KB Time limit exceeded
139 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27696 KB Output is correct
2 Correct 15 ms 27604 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 18 ms 27604 KB Output is correct
5 Correct 15 ms 27612 KB Output is correct
6 Correct 15 ms 27700 KB Output is correct
7 Correct 15 ms 27632 KB Output is correct
8 Correct 15 ms 27588 KB Output is correct
9 Correct 15 ms 27604 KB Output is correct
10 Correct 15 ms 27604 KB Output is correct
11 Correct 16 ms 27680 KB Output is correct
12 Correct 16 ms 27700 KB Output is correct
13 Correct 15 ms 27700 KB Output is correct
14 Correct 15 ms 27604 KB Output is correct
15 Correct 17 ms 27704 KB Output is correct
16 Correct 17 ms 27696 KB Output is correct
17 Correct 20 ms 27724 KB Output is correct
18 Correct 20 ms 27704 KB Output is correct
19 Correct 16 ms 27708 KB Output is correct
20 Correct 16 ms 27736 KB Output is correct
21 Correct 16 ms 27800 KB Output is correct
22 Correct 16 ms 27808 KB Output is correct
23 Correct 16 ms 27740 KB Output is correct
24 Correct 37 ms 36152 KB Output is correct
25 Correct 36 ms 36120 KB Output is correct
26 Correct 36 ms 36172 KB Output is correct
27 Correct 16 ms 27840 KB Output is correct
28 Correct 17 ms 27876 KB Output is correct
29 Correct 17 ms 27848 KB Output is correct
30 Correct 16 ms 27860 KB Output is correct
31 Correct 17 ms 27816 KB Output is correct
32 Correct 17 ms 27840 KB Output is correct
33 Correct 772 ms 29952 KB Output is correct
34 Correct 781 ms 29948 KB Output is correct
35 Correct 784 ms 29952 KB Output is correct
36 Correct 781 ms 29952 KB Output is correct
37 Correct 808 ms 29952 KB Output is correct
38 Correct 804 ms 29948 KB Output is correct
39 Correct 41 ms 36836 KB Output is correct
40 Correct 40 ms 36848 KB Output is correct
41 Correct 40 ms 36884 KB Output is correct
42 Correct 26 ms 28480 KB Output is correct
43 Correct 20 ms 28232 KB Output is correct
44 Correct 21 ms 28628 KB Output is correct
45 Correct 19 ms 28224 KB Output is correct
46 Correct 18 ms 28244 KB Output is correct
47 Correct 21 ms 28664 KB Output is correct
48 Execution timed out 1574 ms 47876 KB Time limit exceeded
49 Halted 0 ms 0 KB -