답안 #802975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802975 2023-08-02T17:00:47 Z radaiosm7 벽 칠하기 (APIO20_paint) C++11
51 / 100
132 ms 23884 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
int n, m, x, y, l, s, i, mn;
int j, cc;
vector<pair<int, int> > segs;
bool ok;
stack<pair<int, int> > S;
vector<int> ava[100005];
int dp[2][5005];
  
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.Y == b.Y) return a.X < b.X;
  return a.Y < b.Y;
}
  
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int> > B) {
  for (i=0; i < M; ++i) for (j=0; j < A[i]; ++j) ava[B[i][j]].push_back(i);
  fill(dp[1], dp[1]+M, 0);

  for (y=0; y < N; ++y) {
    cc = y&1;
    fill(dp[cc], dp[cc]+M, 0);
    ok = false;

    for (auto x : ava[C[y]]) {
      if (x == 0) dp[cc][x] = dp[1-cc][M-1]+1;
      else dp[cc][x] = dp[1-cc][x-1]+1;

      if (!ok && dp[cc][x] >= M) {
        segs.push_back(make_pair(y-M+1, y));
        ok = true;
      }
    }
  }
  
  sort(segs.begin(), segs.end(), cmp);
  s = (int)segs.size();
  if (s == 0) return -1;
  mn = segs[0].X;
  S.push(segs[0]);
  
  for (i=1; i < s; ++i) {
    if (segs[i].X > S.top().Y+1) continue;
    if (segs[i].Y == S.top().Y) continue;
    while (!S.empty() && S.top().X >= segs[i].X) S.pop();
  
    if (!S.empty()) S.push(make_pair(S.top().Y+1, segs[i].Y));
    else S.push(segs[i]);
    mn = min(mn, segs[i].X);
  }
  
  if (mn > 0 || S.top().Y < N-1) return -1;
  return (int)S.size();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2656 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2660 KB Output is correct
17 Correct 1 ms 2656 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2664 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 14 ms 6868 KB Output is correct
23 Correct 14 ms 6860 KB Output is correct
24 Correct 14 ms 6860 KB Output is correct
25 Correct 4 ms 3156 KB Output is correct
26 Correct 4 ms 3156 KB Output is correct
27 Correct 3 ms 3028 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 3 ms 2768 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 9 ms 4308 KB Output is correct
32 Correct 11 ms 4356 KB Output is correct
33 Correct 9 ms 4436 KB Output is correct
34 Correct 9 ms 4308 KB Output is correct
35 Correct 9 ms 4308 KB Output is correct
36 Correct 9 ms 4332 KB Output is correct
37 Correct 18 ms 7244 KB Output is correct
38 Correct 19 ms 7292 KB Output is correct
39 Correct 18 ms 7164 KB Output is correct
40 Correct 13 ms 4984 KB Output is correct
41 Correct 8 ms 4044 KB Output is correct
42 Correct 11 ms 4176 KB Output is correct
43 Correct 7 ms 3412 KB Output is correct
44 Correct 6 ms 3268 KB Output is correct
45 Correct 10 ms 3564 KB Output is correct
46 Runtime error 132 ms 23884 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2656 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2660 KB Output is correct
17 Correct 1 ms 2656 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2664 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2656 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2660 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2656 KB Output is correct
36 Correct 2 ms 2792 KB Output is correct
37 Correct 2 ms 2664 KB Output is correct
38 Correct 2 ms 2656 KB Output is correct
39 Correct 1 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 1 ms 2656 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 2 ms 2596 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 1 ms 2656 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 2 ms 2664 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2660 KB Output is correct
60 Correct 2 ms 2660 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2656 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 1 ms 2656 KB Output is correct
20 Correct 1 ms 2656 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 14 ms 6868 KB Output is correct
25 Correct 14 ms 6860 KB Output is correct
26 Correct 14 ms 6860 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2656 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2660 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 2 ms 2656 KB Output is correct
39 Correct 2 ms 2792 KB Output is correct
40 Correct 2 ms 2664 KB Output is correct
41 Correct 2 ms 2656 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 1 ms 2656 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 2 ms 2596 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 1 ms 2656 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 2 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 2 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 2 ms 2644 KB Output is correct
60 Correct 2 ms 2664 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 2 ms 2660 KB Output is correct
63 Correct 2 ms 2660 KB Output is correct
64 Correct 2 ms 2644 KB Output is correct
65 Correct 3 ms 2772 KB Output is correct
66 Correct 2 ms 2644 KB Output is correct
67 Correct 2 ms 2644 KB Output is correct
68 Correct 2 ms 2644 KB Output is correct
69 Correct 2 ms 2660 KB Output is correct
70 Correct 2 ms 2900 KB Output is correct
71 Correct 2 ms 2900 KB Output is correct
72 Correct 2 ms 2796 KB Output is correct
73 Correct 2 ms 2772 KB Output is correct
74 Correct 2 ms 2856 KB Output is correct
75 Correct 2 ms 2876 KB Output is correct
76 Correct 15 ms 5868 KB Output is correct
77 Correct 14 ms 6428 KB Output is correct
78 Correct 20 ms 6940 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 2 ms 2644 KB Output is correct
81 Correct 2 ms 2652 KB Output is correct
82 Correct 2 ms 2652 KB Output is correct
83 Correct 2 ms 2644 KB Output is correct
84 Correct 3 ms 2924 KB Output is correct
85 Correct 3 ms 2924 KB Output is correct
86 Correct 3 ms 2880 KB Output is correct
87 Correct 3 ms 2920 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 3 ms 2924 KB Output is correct
90 Correct 19 ms 7276 KB Output is correct
91 Correct 21 ms 7244 KB Output is correct
92 Correct 19 ms 7220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2656 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 1 ms 2656 KB Output is correct
20 Correct 1 ms 2656 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 14 ms 6868 KB Output is correct
25 Correct 14 ms 6860 KB Output is correct
26 Correct 14 ms 6860 KB Output is correct
27 Correct 4 ms 3156 KB Output is correct
28 Correct 4 ms 3156 KB Output is correct
29 Correct 3 ms 3028 KB Output is correct
30 Correct 3 ms 2900 KB Output is correct
31 Correct 3 ms 2768 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 9 ms 4308 KB Output is correct
34 Correct 11 ms 4356 KB Output is correct
35 Correct 9 ms 4436 KB Output is correct
36 Correct 9 ms 4308 KB Output is correct
37 Correct 9 ms 4308 KB Output is correct
38 Correct 9 ms 4332 KB Output is correct
39 Correct 18 ms 7244 KB Output is correct
40 Correct 19 ms 7292 KB Output is correct
41 Correct 18 ms 7164 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2656 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2660 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 2 ms 2656 KB Output is correct
54 Correct 2 ms 2792 KB Output is correct
55 Correct 2 ms 2664 KB Output is correct
56 Correct 2 ms 2656 KB Output is correct
57 Correct 1 ms 2644 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 1 ms 2656 KB Output is correct
60 Correct 2 ms 2644 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 1 ms 2644 KB Output is correct
63 Correct 2 ms 2596 KB Output is correct
64 Correct 2 ms 2644 KB Output is correct
65 Correct 2 ms 2644 KB Output is correct
66 Correct 1 ms 2656 KB Output is correct
67 Correct 1 ms 2644 KB Output is correct
68 Correct 1 ms 2644 KB Output is correct
69 Correct 2 ms 2644 KB Output is correct
70 Correct 2 ms 2644 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 2 ms 2644 KB Output is correct
73 Correct 2 ms 2644 KB Output is correct
74 Correct 2 ms 2644 KB Output is correct
75 Correct 2 ms 2664 KB Output is correct
76 Correct 2 ms 2644 KB Output is correct
77 Correct 2 ms 2660 KB Output is correct
78 Correct 2 ms 2660 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 3 ms 2772 KB Output is correct
81 Correct 2 ms 2644 KB Output is correct
82 Correct 2 ms 2644 KB Output is correct
83 Correct 2 ms 2644 KB Output is correct
84 Correct 2 ms 2660 KB Output is correct
85 Correct 2 ms 2900 KB Output is correct
86 Correct 2 ms 2900 KB Output is correct
87 Correct 2 ms 2796 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 2 ms 2856 KB Output is correct
90 Correct 2 ms 2876 KB Output is correct
91 Correct 15 ms 5868 KB Output is correct
92 Correct 14 ms 6428 KB Output is correct
93 Correct 20 ms 6940 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 2 ms 2652 KB Output is correct
97 Correct 2 ms 2652 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 3 ms 2924 KB Output is correct
100 Correct 3 ms 2924 KB Output is correct
101 Correct 3 ms 2880 KB Output is correct
102 Correct 3 ms 2920 KB Output is correct
103 Correct 3 ms 2900 KB Output is correct
104 Correct 3 ms 2924 KB Output is correct
105 Correct 19 ms 7276 KB Output is correct
106 Correct 21 ms 7244 KB Output is correct
107 Correct 19 ms 7220 KB Output is correct
108 Correct 4 ms 3156 KB Output is correct
109 Correct 21 ms 3096 KB Output is correct
110 Correct 13 ms 2864 KB Output is correct
111 Correct 10 ms 2876 KB Output is correct
112 Correct 12 ms 2920 KB Output is correct
113 Correct 9 ms 2900 KB Output is correct
114 Correct 10 ms 4504 KB Output is correct
115 Correct 10 ms 4308 KB Output is correct
116 Correct 13 ms 4900 KB Output is correct
117 Correct 10 ms 4436 KB Output is correct
118 Correct 12 ms 4580 KB Output is correct
119 Correct 10 ms 4244 KB Output is correct
120 Correct 14 ms 5676 KB Output is correct
121 Correct 6 ms 3540 KB Output is correct
122 Correct 16 ms 6068 KB Output is correct
123 Correct 5 ms 3432 KB Output is correct
124 Correct 17 ms 6548 KB Output is correct
125 Correct 7 ms 3832 KB Output is correct
126 Correct 8 ms 3620 KB Output is correct
127 Correct 7 ms 3908 KB Output is correct
128 Correct 5 ms 3420 KB Output is correct
129 Correct 5 ms 3540 KB Output is correct
130 Correct 4 ms 3156 KB Output is correct
131 Correct 29 ms 3276 KB Output is correct
132 Correct 23 ms 2920 KB Output is correct
133 Correct 19 ms 2920 KB Output is correct
134 Correct 22 ms 2900 KB Output is correct
135 Correct 16 ms 3012 KB Output is correct
136 Correct 15 ms 5204 KB Output is correct
137 Correct 15 ms 5204 KB Output is correct
138 Correct 15 ms 5204 KB Output is correct
139 Correct 15 ms 5148 KB Output is correct
140 Correct 15 ms 5144 KB Output is correct
141 Correct 15 ms 5204 KB Output is correct
142 Correct 32 ms 7700 KB Output is correct
143 Correct 12 ms 4076 KB Output is correct
144 Correct 24 ms 7628 KB Output is correct
145 Correct 9 ms 4028 KB Output is correct
146 Correct 24 ms 7628 KB Output is correct
147 Correct 8 ms 4052 KB Output is correct
148 Correct 9 ms 4180 KB Output is correct
149 Correct 8 ms 4052 KB Output is correct
150 Correct 7 ms 3948 KB Output is correct
151 Correct 8 ms 3912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2656 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 1 ms 2656 KB Output is correct
20 Correct 1 ms 2656 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2664 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 14 ms 6868 KB Output is correct
25 Correct 14 ms 6860 KB Output is correct
26 Correct 14 ms 6860 KB Output is correct
27 Correct 4 ms 3156 KB Output is correct
28 Correct 4 ms 3156 KB Output is correct
29 Correct 3 ms 3028 KB Output is correct
30 Correct 3 ms 2900 KB Output is correct
31 Correct 3 ms 2768 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 9 ms 4308 KB Output is correct
34 Correct 11 ms 4356 KB Output is correct
35 Correct 9 ms 4436 KB Output is correct
36 Correct 9 ms 4308 KB Output is correct
37 Correct 9 ms 4308 KB Output is correct
38 Correct 9 ms 4332 KB Output is correct
39 Correct 18 ms 7244 KB Output is correct
40 Correct 19 ms 7292 KB Output is correct
41 Correct 18 ms 7164 KB Output is correct
42 Correct 13 ms 4984 KB Output is correct
43 Correct 8 ms 4044 KB Output is correct
44 Correct 11 ms 4176 KB Output is correct
45 Correct 7 ms 3412 KB Output is correct
46 Correct 6 ms 3268 KB Output is correct
47 Correct 10 ms 3564 KB Output is correct
48 Runtime error 132 ms 23884 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -