답안 #788654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788654 2023-07-20T12:46:24 Z mindiyak 벽 칠하기 (APIO20_paint) C++14
28 / 100
1500 ms 48736 KB
#include "paint.h"

#include <vector>
#include <unordered_set>
#include <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;
  set<pair<int,int>> minimumele;
  vector<set<pair<int,int>>::iterator> remove_arr;
  
  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;
      }
      int minimum = 1000000;
      set<pair<int,int>>::iterator l=minimumele.begin();

      while(l!=minimumele.end()){
        auto minimum_pair = *l;
        if(minimum_pair.second < i){
          remove_arr.push_back(l);
        }else{
          minimum = minimum_pair.first;
          break;
        }
        l++;
      }
      // cout << i << " " << minimum  << " " << remove_arr.size() << endl;
      for(int n=0;n<(int)remove_arr.size();n++){
          minimumele.erase(remove_arr[n]);
      }
      remove_arr.clear();
      dp[(M-1+i)] = min(dp[(M-1+i)],minimum+1);
      minimumele.insert({dp[(M-1+i)], M-1+i});
      // 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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27604 KB Output is correct
2 Correct 15 ms 27608 KB Output is correct
3 Correct 15 ms 27580 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 14 ms 27668 KB Output is correct
6 Correct 14 ms 27624 KB Output is correct
7 Correct 14 ms 27604 KB Output is correct
8 Correct 15 ms 27660 KB Output is correct
9 Correct 17 ms 27604 KB Output is correct
10 Correct 17 ms 27660 KB Output is correct
11 Correct 15 ms 27604 KB Output is correct
12 Correct 15 ms 27696 KB Output is correct
13 Correct 16 ms 27720 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27812 KB Output is correct
16 Correct 15 ms 27712 KB Output is correct
17 Correct 16 ms 27808 KB Output is correct
18 Correct 16 ms 27732 KB Output is correct
19 Correct 15 ms 27752 KB Output is correct
20 Correct 15 ms 27732 KB Output is correct
21 Correct 15 ms 27852 KB Output is correct
22 Correct 40 ms 36236 KB Output is correct
23 Correct 36 ms 36208 KB Output is correct
24 Correct 36 ms 36176 KB Output is correct
25 Correct 17 ms 27836 KB Output is correct
26 Correct 18 ms 27860 KB Output is correct
27 Correct 16 ms 27888 KB Output is correct
28 Correct 17 ms 27860 KB Output is correct
29 Correct 16 ms 27844 KB Output is correct
30 Correct 17 ms 27924 KB Output is correct
31 Correct 724 ms 30020 KB Output is correct
32 Correct 768 ms 30052 KB Output is correct
33 Correct 796 ms 30052 KB Output is correct
34 Correct 784 ms 30028 KB Output is correct
35 Correct 751 ms 30060 KB Output is correct
36 Correct 731 ms 30056 KB Output is correct
37 Correct 42 ms 36812 KB Output is correct
38 Correct 39 ms 36824 KB Output is correct
39 Correct 42 ms 36836 KB Output is correct
40 Correct 24 ms 28492 KB Output is correct
41 Correct 26 ms 28232 KB Output is correct
42 Correct 22 ms 28656 KB Output is correct
43 Correct 19 ms 28244 KB Output is correct
44 Correct 20 ms 28244 KB Output is correct
45 Correct 21 ms 28616 KB Output is correct
46 Execution timed out 1572 ms 48736 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27604 KB Output is correct
2 Correct 15 ms 27608 KB Output is correct
3 Correct 15 ms 27580 KB Output is correct
4 Correct 15 ms 27648 KB Output is correct
5 Correct 14 ms 27668 KB Output is correct
6 Correct 14 ms 27624 KB Output is correct
7 Correct 14 ms 27604 KB Output is correct
8 Correct 15 ms 27660 KB Output is correct
9 Correct 17 ms 27604 KB Output is correct
10 Correct 17 ms 27660 KB Output is correct
11 Correct 15 ms 27604 KB Output is correct
12 Correct 15 ms 27696 KB Output is correct
13 Correct 16 ms 27720 KB Output is correct
14 Correct 15 ms 27688 KB Output is correct
15 Correct 16 ms 27812 KB Output is correct
16 Correct 15 ms 27712 KB Output is correct
17 Correct 16 ms 27808 KB Output is correct
18 Correct 16 ms 27732 KB Output is correct
19 Correct 15 ms 27752 KB Output is correct
20 Correct 15 ms 27732 KB Output is correct
21 Correct 15 ms 27852 KB Output is correct
22 Correct 17 ms 27620 KB Output is correct
23 Correct 15 ms 27620 KB Output is correct
24 Correct 15 ms 27604 KB Output is correct
25 Correct 14 ms 27692 KB Output is correct
26 Correct 15 ms 27712 KB Output is correct
27 Correct 17 ms 27696 KB Output is correct
28 Correct 15 ms 27604 KB Output is correct
29 Correct 15 ms 27636 KB Output is correct
30 Correct 16 ms 27604 KB Output is correct
31 Correct 15 ms 27604 KB Output is correct
32 Correct 15 ms 27604 KB Output is correct
33 Correct 16 ms 27732 KB Output is correct
34 Correct 16 ms 27712 KB Output is correct
35 Correct 16 ms 27692 KB Output is correct
36 Correct 16 ms 27752 KB Output is correct
37 Correct 16 ms 27712 KB Output is correct
38 Correct 16 ms 27720 KB Output is correct
39 Correct 15 ms 27604 KB Output is correct
40 Correct 20 ms 27720 KB Output is correct
41 Correct 16 ms 27732 KB Output is correct
42 Correct 15 ms 27720 KB Output is correct
43 Correct 15 ms 27700 KB Output is correct
44 Correct 16 ms 27604 KB Output is correct
45 Correct 15 ms 27716 KB Output is correct
46 Correct 16 ms 27732 KB Output is correct
47 Correct 16 ms 27708 KB Output is correct
48 Correct 16 ms 27688 KB Output is correct
49 Correct 15 ms 27732 KB Output is correct
50 Correct 16 ms 27748 KB Output is correct
51 Correct 17 ms 27720 KB Output is correct
52 Correct 17 ms 27732 KB Output is correct
53 Correct 20 ms 27724 KB Output is correct
54 Correct 17 ms 27732 KB Output is correct
55 Correct 17 ms 27732 KB Output is correct
56 Correct 16 ms 27768 KB Output is correct
57 Correct 16 ms 27688 KB Output is correct
58 Correct 18 ms 27848 KB Output is correct
59 Correct 16 ms 27724 KB Output is correct
60 Correct 16 ms 27752 KB Output is correct
61 Correct 16 ms 27692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 27620 KB Output is correct
2 Correct 15 ms 27620 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 15 ms 27608 KB Output is correct
5 Correct 15 ms 27580 KB Output is correct
6 Correct 15 ms 27648 KB Output is correct
7 Correct 14 ms 27668 KB Output is correct
8 Correct 14 ms 27624 KB Output is correct
9 Correct 14 ms 27604 KB Output is correct
10 Correct 15 ms 27660 KB Output is correct
11 Correct 17 ms 27604 KB Output is correct
12 Correct 17 ms 27660 KB Output is correct
13 Correct 15 ms 27604 KB Output is correct
14 Correct 15 ms 27696 KB Output is correct
15 Correct 16 ms 27720 KB Output is correct
16 Correct 15 ms 27688 KB Output is correct
17 Correct 16 ms 27812 KB Output is correct
18 Correct 15 ms 27712 KB Output is correct
19 Correct 16 ms 27808 KB Output is correct
20 Correct 16 ms 27732 KB Output is correct
21 Correct 15 ms 27752 KB Output is correct
22 Correct 15 ms 27732 KB Output is correct
23 Correct 15 ms 27852 KB Output is correct
24 Correct 40 ms 36236 KB Output is correct
25 Correct 36 ms 36208 KB Output is correct
26 Correct 36 ms 36176 KB Output is correct
27 Correct 15 ms 27604 KB Output is correct
28 Correct 14 ms 27692 KB Output is correct
29 Correct 15 ms 27712 KB Output is correct
30 Correct 17 ms 27696 KB Output is correct
31 Correct 15 ms 27604 KB Output is correct
32 Correct 15 ms 27636 KB Output is correct
33 Correct 16 ms 27604 KB Output is correct
34 Correct 15 ms 27604 KB Output is correct
35 Correct 15 ms 27604 KB Output is correct
36 Correct 16 ms 27732 KB Output is correct
37 Correct 16 ms 27712 KB Output is correct
38 Correct 16 ms 27692 KB Output is correct
39 Correct 16 ms 27752 KB Output is correct
40 Correct 16 ms 27712 KB Output is correct
41 Correct 16 ms 27720 KB Output is correct
42 Correct 15 ms 27604 KB Output is correct
43 Correct 20 ms 27720 KB Output is correct
44 Correct 16 ms 27732 KB Output is correct
45 Correct 15 ms 27720 KB Output is correct
46 Correct 15 ms 27700 KB Output is correct
47 Correct 16 ms 27604 KB Output is correct
48 Correct 15 ms 27716 KB Output is correct
49 Correct 16 ms 27732 KB Output is correct
50 Correct 16 ms 27708 KB Output is correct
51 Correct 16 ms 27688 KB Output is correct
52 Correct 15 ms 27732 KB Output is correct
53 Correct 16 ms 27748 KB Output is correct
54 Correct 17 ms 27720 KB Output is correct
55 Correct 17 ms 27732 KB Output is correct
56 Correct 20 ms 27724 KB Output is correct
57 Correct 17 ms 27732 KB Output is correct
58 Correct 17 ms 27732 KB Output is correct
59 Correct 16 ms 27768 KB Output is correct
60 Correct 16 ms 27688 KB Output is correct
61 Correct 18 ms 27848 KB Output is correct
62 Correct 16 ms 27724 KB Output is correct
63 Correct 16 ms 27752 KB Output is correct
64 Correct 16 ms 27692 KB Output is correct
65 Correct 16 ms 27732 KB Output is correct
66 Correct 15 ms 27712 KB Output is correct
67 Correct 16 ms 27732 KB Output is correct
68 Correct 15 ms 27724 KB Output is correct
69 Correct 15 ms 27712 KB Output is correct
70 Correct 22 ms 28388 KB Output is correct
71 Correct 20 ms 28364 KB Output is correct
72 Correct 20 ms 28316 KB Output is correct
73 Correct 18 ms 28048 KB Output is correct
74 Correct 19 ms 28296 KB Output is correct
75 Correct 20 ms 28288 KB Output is correct
76 Correct 40 ms 35444 KB Output is correct
77 Correct 40 ms 36256 KB Output is correct
78 Correct 51 ms 37828 KB Output is correct
79 Correct 16 ms 27732 KB Output is correct
80 Correct 16 ms 27744 KB Output is correct
81 Correct 16 ms 27732 KB Output is correct
82 Correct 16 ms 27704 KB Output is correct
83 Correct 18 ms 27716 KB Output is correct
84 Correct 21 ms 28628 KB Output is correct
85 Correct 23 ms 28628 KB Output is correct
86 Correct 22 ms 28564 KB Output is correct
87 Correct 21 ms 28648 KB Output is correct
88 Correct 23 ms 28652 KB Output is correct
89 Correct 21 ms 28620 KB Output is correct
90 Correct 53 ms 38896 KB Output is correct
91 Correct 66 ms 38856 KB Output is correct
92 Correct 52 ms 38952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 27620 KB Output is correct
2 Correct 15 ms 27620 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 15 ms 27608 KB Output is correct
5 Correct 15 ms 27580 KB Output is correct
6 Correct 15 ms 27648 KB Output is correct
7 Correct 14 ms 27668 KB Output is correct
8 Correct 14 ms 27624 KB Output is correct
9 Correct 14 ms 27604 KB Output is correct
10 Correct 15 ms 27660 KB Output is correct
11 Correct 17 ms 27604 KB Output is correct
12 Correct 17 ms 27660 KB Output is correct
13 Correct 15 ms 27604 KB Output is correct
14 Correct 15 ms 27696 KB Output is correct
15 Correct 16 ms 27720 KB Output is correct
16 Correct 15 ms 27688 KB Output is correct
17 Correct 16 ms 27812 KB Output is correct
18 Correct 15 ms 27712 KB Output is correct
19 Correct 16 ms 27808 KB Output is correct
20 Correct 16 ms 27732 KB Output is correct
21 Correct 15 ms 27752 KB Output is correct
22 Correct 15 ms 27732 KB Output is correct
23 Correct 15 ms 27852 KB Output is correct
24 Correct 40 ms 36236 KB Output is correct
25 Correct 36 ms 36208 KB Output is correct
26 Correct 36 ms 36176 KB Output is correct
27 Correct 17 ms 27836 KB Output is correct
28 Correct 18 ms 27860 KB Output is correct
29 Correct 16 ms 27888 KB Output is correct
30 Correct 17 ms 27860 KB Output is correct
31 Correct 16 ms 27844 KB Output is correct
32 Correct 17 ms 27924 KB Output is correct
33 Correct 724 ms 30020 KB Output is correct
34 Correct 768 ms 30052 KB Output is correct
35 Correct 796 ms 30052 KB Output is correct
36 Correct 784 ms 30028 KB Output is correct
37 Correct 751 ms 30060 KB Output is correct
38 Correct 731 ms 30056 KB Output is correct
39 Correct 42 ms 36812 KB Output is correct
40 Correct 39 ms 36824 KB Output is correct
41 Correct 42 ms 36836 KB Output is correct
42 Correct 15 ms 27604 KB Output is correct
43 Correct 14 ms 27692 KB Output is correct
44 Correct 15 ms 27712 KB Output is correct
45 Correct 17 ms 27696 KB Output is correct
46 Correct 15 ms 27604 KB Output is correct
47 Correct 15 ms 27636 KB Output is correct
48 Correct 16 ms 27604 KB Output is correct
49 Correct 15 ms 27604 KB Output is correct
50 Correct 15 ms 27604 KB Output is correct
51 Correct 16 ms 27732 KB Output is correct
52 Correct 16 ms 27712 KB Output is correct
53 Correct 16 ms 27692 KB Output is correct
54 Correct 16 ms 27752 KB Output is correct
55 Correct 16 ms 27712 KB Output is correct
56 Correct 16 ms 27720 KB Output is correct
57 Correct 15 ms 27604 KB Output is correct
58 Correct 20 ms 27720 KB Output is correct
59 Correct 16 ms 27732 KB Output is correct
60 Correct 15 ms 27720 KB Output is correct
61 Correct 15 ms 27700 KB Output is correct
62 Correct 16 ms 27604 KB Output is correct
63 Correct 15 ms 27716 KB Output is correct
64 Correct 16 ms 27732 KB Output is correct
65 Correct 16 ms 27708 KB Output is correct
66 Correct 16 ms 27688 KB Output is correct
67 Correct 15 ms 27732 KB Output is correct
68 Correct 16 ms 27748 KB Output is correct
69 Correct 17 ms 27720 KB Output is correct
70 Correct 17 ms 27732 KB Output is correct
71 Correct 20 ms 27724 KB Output is correct
72 Correct 17 ms 27732 KB Output is correct
73 Correct 17 ms 27732 KB Output is correct
74 Correct 16 ms 27768 KB Output is correct
75 Correct 16 ms 27688 KB Output is correct
76 Correct 18 ms 27848 KB Output is correct
77 Correct 16 ms 27724 KB Output is correct
78 Correct 16 ms 27752 KB Output is correct
79 Correct 16 ms 27692 KB Output is correct
80 Correct 16 ms 27732 KB Output is correct
81 Correct 15 ms 27712 KB Output is correct
82 Correct 16 ms 27732 KB Output is correct
83 Correct 15 ms 27724 KB Output is correct
84 Correct 15 ms 27712 KB Output is correct
85 Correct 22 ms 28388 KB Output is correct
86 Correct 20 ms 28364 KB Output is correct
87 Correct 20 ms 28316 KB Output is correct
88 Correct 18 ms 28048 KB Output is correct
89 Correct 19 ms 28296 KB Output is correct
90 Correct 20 ms 28288 KB Output is correct
91 Correct 40 ms 35444 KB Output is correct
92 Correct 40 ms 36256 KB Output is correct
93 Correct 51 ms 37828 KB Output is correct
94 Correct 16 ms 27732 KB Output is correct
95 Correct 16 ms 27744 KB Output is correct
96 Correct 16 ms 27732 KB Output is correct
97 Correct 16 ms 27704 KB Output is correct
98 Correct 18 ms 27716 KB Output is correct
99 Correct 21 ms 28628 KB Output is correct
100 Correct 23 ms 28628 KB Output is correct
101 Correct 22 ms 28564 KB Output is correct
102 Correct 21 ms 28648 KB Output is correct
103 Correct 23 ms 28652 KB Output is correct
104 Correct 21 ms 28620 KB Output is correct
105 Correct 53 ms 38896 KB Output is correct
106 Correct 66 ms 38856 KB Output is correct
107 Correct 52 ms 38952 KB Output is correct
108 Correct 20 ms 27852 KB Output is correct
109 Correct 91 ms 28068 KB Output is correct
110 Correct 230 ms 27976 KB Output is correct
111 Correct 153 ms 28040 KB Output is correct
112 Correct 160 ms 28116 KB Output is correct
113 Correct 92 ms 28252 KB Output is correct
114 Correct 542 ms 31512 KB Output is correct
115 Correct 64 ms 31596 KB Output is correct
116 Correct 428 ms 32640 KB Output is correct
117 Correct 351 ms 31512 KB Output is correct
118 Correct 71 ms 32044 KB Output is correct
119 Correct 700 ms 31048 KB Output is correct
120 Correct 39 ms 34508 KB Output is correct
121 Correct 350 ms 29172 KB Output is correct
122 Correct 46 ms 35912 KB Output is correct
123 Correct 126 ms 28748 KB Output is correct
124 Correct 47 ms 36852 KB Output is correct
125 Correct 78 ms 29336 KB Output is correct
126 Correct 27 ms 29632 KB Output is correct
127 Correct 168 ms 30136 KB Output is correct
128 Correct 49 ms 29496 KB Output is correct
129 Correct 61 ms 29436 KB Output is correct
130 Correct 17 ms 27796 KB Output is correct
131 Correct 124 ms 28140 KB Output is correct
132 Correct 361 ms 28152 KB Output is correct
133 Correct 260 ms 28192 KB Output is correct
134 Correct 206 ms 28244 KB Output is correct
135 Correct 175 ms 28244 KB Output is correct
136 Execution timed out 1536 ms 33552 KB Time limit exceeded
137 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 27620 KB Output is correct
2 Correct 15 ms 27620 KB Output is correct
3 Correct 15 ms 27604 KB Output is correct
4 Correct 15 ms 27608 KB Output is correct
5 Correct 15 ms 27580 KB Output is correct
6 Correct 15 ms 27648 KB Output is correct
7 Correct 14 ms 27668 KB Output is correct
8 Correct 14 ms 27624 KB Output is correct
9 Correct 14 ms 27604 KB Output is correct
10 Correct 15 ms 27660 KB Output is correct
11 Correct 17 ms 27604 KB Output is correct
12 Correct 17 ms 27660 KB Output is correct
13 Correct 15 ms 27604 KB Output is correct
14 Correct 15 ms 27696 KB Output is correct
15 Correct 16 ms 27720 KB Output is correct
16 Correct 15 ms 27688 KB Output is correct
17 Correct 16 ms 27812 KB Output is correct
18 Correct 15 ms 27712 KB Output is correct
19 Correct 16 ms 27808 KB Output is correct
20 Correct 16 ms 27732 KB Output is correct
21 Correct 15 ms 27752 KB Output is correct
22 Correct 15 ms 27732 KB Output is correct
23 Correct 15 ms 27852 KB Output is correct
24 Correct 40 ms 36236 KB Output is correct
25 Correct 36 ms 36208 KB Output is correct
26 Correct 36 ms 36176 KB Output is correct
27 Correct 17 ms 27836 KB Output is correct
28 Correct 18 ms 27860 KB Output is correct
29 Correct 16 ms 27888 KB Output is correct
30 Correct 17 ms 27860 KB Output is correct
31 Correct 16 ms 27844 KB Output is correct
32 Correct 17 ms 27924 KB Output is correct
33 Correct 724 ms 30020 KB Output is correct
34 Correct 768 ms 30052 KB Output is correct
35 Correct 796 ms 30052 KB Output is correct
36 Correct 784 ms 30028 KB Output is correct
37 Correct 751 ms 30060 KB Output is correct
38 Correct 731 ms 30056 KB Output is correct
39 Correct 42 ms 36812 KB Output is correct
40 Correct 39 ms 36824 KB Output is correct
41 Correct 42 ms 36836 KB Output is correct
42 Correct 24 ms 28492 KB Output is correct
43 Correct 26 ms 28232 KB Output is correct
44 Correct 22 ms 28656 KB Output is correct
45 Correct 19 ms 28244 KB Output is correct
46 Correct 20 ms 28244 KB Output is correct
47 Correct 21 ms 28616 KB Output is correct
48 Execution timed out 1572 ms 48736 KB Time limit exceeded
49 Halted 0 ms 0 KB -