답안 #902431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902431 2024-01-10T11:57:58 Z nguyentunglam 벽 칠하기 (APIO20_paint) C++17
51 / 100
1500 ms 17244 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 2e5 + 10;

bool good[N];

int n, m, k;

int f[N], g[N], bit[N], dp[N];

vector<int> color[N];

int minimumInstructions(int N, int M, int K, std::vector<int> c, std::vector<int> a, std::vector<std::vector<int>> b) {
  n = N; m = M; k = K;
  for(int i = 0; i < m; i++) {
    for(int &j : b[i]) {
      color[j].push_back(i);
    }
  }
  for(int i = n - 1; i >= 0; i--) {
    for(int &j : color[c[i]]) {
      f[j] = g[(j + 1) % m] + 1;
      if (f[j] >= m) good[i] = 1;
    }
    if (i + 1 < n) for(int &j : color[c[i + 1]]) g[j] = 0;
    for(int &j : color[c[i]]) {
      g[j] = f[j];
      f[j] = 0;
    }
//    if (i == 5) cout << g[0] << endl;
  }
//  for(int i = 0; i < n; i++) cout << good[i] << " "; cout << endl;

  for(int i = 0; i < n; i++) dp[i] = 1e9;

  if (!good[n - m]) return -1;

  dp[n - m] = 1;

  for(int i = n - m - 1; i >= 0; i--) {
    if (good[i]) for(int j = i + 1; j <= i + m; j++) dp[i] = min(dp[i], dp[j] + 1);
//    cout << dp[i] << " " << i << endl;
  }

  if (dp[0] > 1e8) return -1;

  return dp[0];
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

  int n, m, k;
  cin >> n >> m >> k;

  vector<int> c(n), a(m);

  vector<vector<int> > b;

  for(int i = 0; i < n; i++) cin >> c[i];

//  for(int i = 0; i < n; i++) cout << c[i] << " "; cout << endl;

  for(int i = 0; i < m; i++) {
    cin >> a[i];
    vector<int> tmp(a[i]);
    for(int j = 0; j < a[i]; j++) cin >> tmp[j];
    b.push_back(tmp);
  }
  cout << minimumInstructions(n, m, k, c, a, b);
}
#endif // ngu

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6760 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 1 ms 6756 KB Output is correct
6 Correct 1 ms 6760 KB Output is correct
7 Correct 2 ms 6760 KB Output is correct
8 Correct 1 ms 6788 KB Output is correct
9 Correct 1 ms 6760 KB Output is correct
10 Correct 2 ms 6760 KB Output is correct
11 Correct 1 ms 6760 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6776 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 7012 KB Output is correct
19 Correct 2 ms 7000 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 19 ms 11060 KB Output is correct
23 Correct 16 ms 11100 KB Output is correct
24 Correct 19 ms 11096 KB Output is correct
25 Correct 3 ms 7004 KB Output is correct
26 Correct 4 ms 6760 KB Output is correct
27 Correct 3 ms 6760 KB Output is correct
28 Correct 4 ms 6760 KB Output is correct
29 Correct 3 ms 6760 KB Output is correct
30 Correct 3 ms 6760 KB Output is correct
31 Correct 46 ms 8040 KB Output is correct
32 Correct 43 ms 8040 KB Output is correct
33 Correct 44 ms 8112 KB Output is correct
34 Correct 47 ms 8040 KB Output is correct
35 Correct 44 ms 8028 KB Output is correct
36 Correct 43 ms 8024 KB Output is correct
37 Correct 19 ms 11648 KB Output is correct
38 Correct 19 ms 11568 KB Output is correct
39 Correct 20 ms 11600 KB Output is correct
40 Correct 9 ms 7520 KB Output is correct
41 Correct 6 ms 7272 KB Output is correct
42 Correct 10 ms 7784 KB Output is correct
43 Correct 7 ms 7256 KB Output is correct
44 Correct 6 ms 7260 KB Output is correct
45 Correct 8 ms 7628 KB Output is correct
46 Execution timed out 1565 ms 17244 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6760 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 1 ms 6756 KB Output is correct
6 Correct 1 ms 6760 KB Output is correct
7 Correct 2 ms 6760 KB Output is correct
8 Correct 1 ms 6788 KB Output is correct
9 Correct 1 ms 6760 KB Output is correct
10 Correct 2 ms 6760 KB Output is correct
11 Correct 1 ms 6760 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6776 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 7012 KB Output is correct
19 Correct 2 ms 7000 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6772 KB Output is correct
30 Correct 1 ms 6744 KB Output is correct
31 Correct 1 ms 6744 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6744 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6780 KB Output is correct
40 Correct 2 ms 6760 KB Output is correct
41 Correct 2 ms 6892 KB Output is correct
42 Correct 2 ms 6760 KB Output is correct
43 Correct 2 ms 6744 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6756 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 2 ms 6760 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6744 KB Output is correct
52 Correct 2 ms 6744 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6760 KB Output is correct
55 Correct 2 ms 6760 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 2 ms 6748 KB Output is correct
61 Correct 2 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6760 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 1 ms 6756 KB Output is correct
8 Correct 1 ms 6760 KB Output is correct
9 Correct 2 ms 6760 KB Output is correct
10 Correct 1 ms 6788 KB Output is correct
11 Correct 1 ms 6760 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 1 ms 6760 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6776 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 7012 KB Output is correct
21 Correct 2 ms 7000 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 19 ms 11060 KB Output is correct
25 Correct 16 ms 11100 KB Output is correct
26 Correct 19 ms 11096 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 1 ms 6748 KB Output is correct
32 Correct 1 ms 6772 KB Output is correct
33 Correct 1 ms 6744 KB Output is correct
34 Correct 1 ms 6744 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6744 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6780 KB Output is correct
43 Correct 2 ms 6760 KB Output is correct
44 Correct 2 ms 6892 KB Output is correct
45 Correct 2 ms 6760 KB Output is correct
46 Correct 2 ms 6744 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6756 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6760 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6744 KB Output is correct
55 Correct 2 ms 6744 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6760 KB Output is correct
58 Correct 2 ms 6760 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 2 ms 6748 KB Output is correct
61 Correct 2 ms 6748 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
64 Correct 2 ms 6744 KB Output is correct
65 Correct 3 ms 6748 KB Output is correct
66 Correct 2 ms 6748 KB Output is correct
67 Correct 2 ms 6748 KB Output is correct
68 Correct 2 ms 6744 KB Output is correct
69 Correct 3 ms 6748 KB Output is correct
70 Correct 3 ms 7000 KB Output is correct
71 Correct 3 ms 7004 KB Output is correct
72 Correct 3 ms 6848 KB Output is correct
73 Correct 2 ms 6748 KB Output is correct
74 Correct 2 ms 7016 KB Output is correct
75 Correct 2 ms 7004 KB Output is correct
76 Correct 15 ms 9984 KB Output is correct
77 Correct 15 ms 10588 KB Output is correct
78 Correct 23 ms 10876 KB Output is correct
79 Correct 2 ms 6744 KB Output is correct
80 Correct 2 ms 6744 KB Output is correct
81 Correct 3 ms 6748 KB Output is correct
82 Correct 2 ms 6748 KB Output is correct
83 Correct 2 ms 6816 KB Output is correct
84 Correct 3 ms 7004 KB Output is correct
85 Correct 3 ms 7000 KB Output is correct
86 Correct 5 ms 7004 KB Output is correct
87 Correct 3 ms 7004 KB Output is correct
88 Correct 3 ms 7040 KB Output is correct
89 Correct 3 ms 7040 KB Output is correct
90 Correct 25 ms 11372 KB Output is correct
91 Correct 21 ms 11356 KB Output is correct
92 Correct 22 ms 11344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6760 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 1 ms 6756 KB Output is correct
8 Correct 1 ms 6760 KB Output is correct
9 Correct 2 ms 6760 KB Output is correct
10 Correct 1 ms 6788 KB Output is correct
11 Correct 1 ms 6760 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 1 ms 6760 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6776 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 7012 KB Output is correct
21 Correct 2 ms 7000 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 19 ms 11060 KB Output is correct
25 Correct 16 ms 11100 KB Output is correct
26 Correct 19 ms 11096 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 4 ms 6760 KB Output is correct
29 Correct 3 ms 6760 KB Output is correct
30 Correct 4 ms 6760 KB Output is correct
31 Correct 3 ms 6760 KB Output is correct
32 Correct 3 ms 6760 KB Output is correct
33 Correct 46 ms 8040 KB Output is correct
34 Correct 43 ms 8040 KB Output is correct
35 Correct 44 ms 8112 KB Output is correct
36 Correct 47 ms 8040 KB Output is correct
37 Correct 44 ms 8028 KB Output is correct
38 Correct 43 ms 8024 KB Output is correct
39 Correct 19 ms 11648 KB Output is correct
40 Correct 19 ms 11568 KB Output is correct
41 Correct 20 ms 11600 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6772 KB Output is correct
48 Correct 1 ms 6744 KB Output is correct
49 Correct 1 ms 6744 KB Output is correct
50 Correct 1 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 2 ms 6744 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 2 ms 6780 KB Output is correct
58 Correct 2 ms 6760 KB Output is correct
59 Correct 2 ms 6892 KB Output is correct
60 Correct 2 ms 6760 KB Output is correct
61 Correct 2 ms 6744 KB Output is correct
62 Correct 1 ms 6748 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
64 Correct 2 ms 6756 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 2 ms 6760 KB Output is correct
67 Correct 2 ms 6748 KB Output is correct
68 Correct 2 ms 6748 KB Output is correct
69 Correct 2 ms 6744 KB Output is correct
70 Correct 2 ms 6744 KB Output is correct
71 Correct 2 ms 6748 KB Output is correct
72 Correct 2 ms 6760 KB Output is correct
73 Correct 2 ms 6760 KB Output is correct
74 Correct 2 ms 6748 KB Output is correct
75 Correct 2 ms 6748 KB Output is correct
76 Correct 2 ms 6748 KB Output is correct
77 Correct 2 ms 6748 KB Output is correct
78 Correct 2 ms 6748 KB Output is correct
79 Correct 2 ms 6744 KB Output is correct
80 Correct 3 ms 6748 KB Output is correct
81 Correct 2 ms 6748 KB Output is correct
82 Correct 2 ms 6748 KB Output is correct
83 Correct 2 ms 6744 KB Output is correct
84 Correct 3 ms 6748 KB Output is correct
85 Correct 3 ms 7000 KB Output is correct
86 Correct 3 ms 7004 KB Output is correct
87 Correct 3 ms 6848 KB Output is correct
88 Correct 2 ms 6748 KB Output is correct
89 Correct 2 ms 7016 KB Output is correct
90 Correct 2 ms 7004 KB Output is correct
91 Correct 15 ms 9984 KB Output is correct
92 Correct 15 ms 10588 KB Output is correct
93 Correct 23 ms 10876 KB Output is correct
94 Correct 2 ms 6744 KB Output is correct
95 Correct 2 ms 6744 KB Output is correct
96 Correct 3 ms 6748 KB Output is correct
97 Correct 2 ms 6748 KB Output is correct
98 Correct 2 ms 6816 KB Output is correct
99 Correct 3 ms 7004 KB Output is correct
100 Correct 3 ms 7000 KB Output is correct
101 Correct 5 ms 7004 KB Output is correct
102 Correct 3 ms 7004 KB Output is correct
103 Correct 3 ms 7040 KB Output is correct
104 Correct 3 ms 7040 KB Output is correct
105 Correct 25 ms 11372 KB Output is correct
106 Correct 21 ms 11356 KB Output is correct
107 Correct 22 ms 11344 KB Output is correct
108 Correct 3 ms 6748 KB Output is correct
109 Correct 62 ms 7012 KB Output is correct
110 Correct 30 ms 6744 KB Output is correct
111 Correct 24 ms 6780 KB Output is correct
112 Correct 27 ms 7004 KB Output is correct
113 Correct 19 ms 7016 KB Output is correct
114 Correct 23 ms 8440 KB Output is correct
115 Correct 14 ms 8284 KB Output is correct
116 Correct 25 ms 8652 KB Output is correct
117 Correct 17 ms 8284 KB Output is correct
118 Correct 11 ms 8280 KB Output is correct
119 Correct 28 ms 8028 KB Output is correct
120 Correct 19 ms 9820 KB Output is correct
121 Correct 28 ms 7480 KB Output is correct
122 Correct 27 ms 10068 KB Output is correct
123 Correct 14 ms 7260 KB Output is correct
124 Correct 19 ms 10580 KB Output is correct
125 Correct 12 ms 7516 KB Output is correct
126 Correct 6 ms 7768 KB Output is correct
127 Correct 7 ms 8028 KB Output is correct
128 Correct 7 ms 7516 KB Output is correct
129 Correct 6 ms 7516 KB Output is correct
130 Correct 4 ms 6756 KB Output is correct
131 Correct 87 ms 7016 KB Output is correct
132 Correct 54 ms 7000 KB Output is correct
133 Correct 44 ms 7080 KB Output is correct
134 Correct 41 ms 7100 KB Output is correct
135 Correct 34 ms 7128 KB Output is correct
136 Correct 55 ms 8956 KB Output is correct
137 Correct 49 ms 8804 KB Output is correct
138 Correct 51 ms 8952 KB Output is correct
139 Correct 49 ms 8800 KB Output is correct
140 Correct 49 ms 8792 KB Output is correct
141 Correct 58 ms 8792 KB Output is correct
142 Correct 24 ms 11608 KB Output is correct
143 Correct 41 ms 7768 KB Output is correct
144 Correct 40 ms 11624 KB Output is correct
145 Correct 44 ms 7772 KB Output is correct
146 Correct 24 ms 11608 KB Output is correct
147 Correct 43 ms 7772 KB Output is correct
148 Correct 9 ms 8244 KB Output is correct
149 Correct 8 ms 8028 KB Output is correct
150 Correct 9 ms 8028 KB Output is correct
151 Correct 7 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6760 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 1 ms 6756 KB Output is correct
8 Correct 1 ms 6760 KB Output is correct
9 Correct 2 ms 6760 KB Output is correct
10 Correct 1 ms 6788 KB Output is correct
11 Correct 1 ms 6760 KB Output is correct
12 Correct 2 ms 6760 KB Output is correct
13 Correct 1 ms 6760 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6776 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 7012 KB Output is correct
21 Correct 2 ms 7000 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 19 ms 11060 KB Output is correct
25 Correct 16 ms 11100 KB Output is correct
26 Correct 19 ms 11096 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 4 ms 6760 KB Output is correct
29 Correct 3 ms 6760 KB Output is correct
30 Correct 4 ms 6760 KB Output is correct
31 Correct 3 ms 6760 KB Output is correct
32 Correct 3 ms 6760 KB Output is correct
33 Correct 46 ms 8040 KB Output is correct
34 Correct 43 ms 8040 KB Output is correct
35 Correct 44 ms 8112 KB Output is correct
36 Correct 47 ms 8040 KB Output is correct
37 Correct 44 ms 8028 KB Output is correct
38 Correct 43 ms 8024 KB Output is correct
39 Correct 19 ms 11648 KB Output is correct
40 Correct 19 ms 11568 KB Output is correct
41 Correct 20 ms 11600 KB Output is correct
42 Correct 9 ms 7520 KB Output is correct
43 Correct 6 ms 7272 KB Output is correct
44 Correct 10 ms 7784 KB Output is correct
45 Correct 7 ms 7256 KB Output is correct
46 Correct 6 ms 7260 KB Output is correct
47 Correct 8 ms 7628 KB Output is correct
48 Execution timed out 1565 ms 17244 KB Time limit exceeded
49 Halted 0 ms 0 KB -