Submission #802694

# Submission time Handle Problem Language Result Execution time Memory
802694 2023-08-02T13:27:52 Z radaiosm7 Painting Walls (APIO20_paint) C++11
28 / 100
1500 ms 7800 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;
vector<pair<int, int> > segs;
bool ok;
stack<pair<int, int> > S;

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 (y=0; y <= N-M; ++y) {
    for (x=0; x < M; ++x) {
      ok = true;
      for (l=0; l < M && ok; ++l) ok &= binary_search(B[(x+l)%M].begin(), B[(x+l)%M].end(), C[y+l]);
      if (!ok) continue;
      segs.push_back(make_pair(y, y+M-1));
      break;
    }
  }

  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();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 284 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 216 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 13 ms 1644 KB Output is correct
23 Correct 12 ms 1620 KB Output is correct
24 Correct 11 ms 1676 KB Output is correct
25 Correct 3 ms 824 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 3 ms 692 KB Output is correct
28 Correct 2 ms 440 KB Output is correct
29 Correct 2 ms 480 KB Output is correct
30 Correct 4 ms 436 KB Output is correct
31 Correct 697 ms 1328 KB Output is correct
32 Correct 679 ms 1316 KB Output is correct
33 Correct 671 ms 1364 KB Output is correct
34 Correct 674 ms 1328 KB Output is correct
35 Correct 695 ms 1348 KB Output is correct
36 Correct 680 ms 1356 KB Output is correct
37 Correct 994 ms 2088 KB Output is correct
38 Correct 969 ms 2080 KB Output is correct
39 Correct 985 ms 2084 KB Output is correct
40 Correct 13 ms 2628 KB Output is correct
41 Correct 9 ms 1752 KB Output is correct
42 Correct 17 ms 1800 KB Output is correct
43 Correct 7 ms 1012 KB Output is correct
44 Correct 8 ms 900 KB Output is correct
45 Correct 13 ms 1236 KB Output is correct
46 Execution timed out 1556 ms 7800 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 228 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 284 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 216 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 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 296 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 360 KB Output is correct
42 Correct 1 ms 304 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 304 KB Output is correct
45 Correct 1 ms 304 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 2 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 1 ms 304 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 1 ms 228 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 284 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 2 ms 304 KB Output is correct
22 Correct 2 ms 216 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 13 ms 1644 KB Output is correct
25 Correct 12 ms 1620 KB Output is correct
26 Correct 11 ms 1676 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 296 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 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 360 KB Output is correct
45 Correct 1 ms 304 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 1 ms 304 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 2 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 296 KB Output is correct
70 Correct 7 ms 372 KB Output is correct
71 Correct 4 ms 468 KB Output is correct
72 Correct 2 ms 460 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 3 ms 340 KB Output is correct
75 Correct 4 ms 340 KB Output is correct
76 Correct 12 ms 1736 KB Output is correct
77 Correct 11 ms 1924 KB Output is correct
78 Correct 11 ms 2124 KB Output is correct
79 Correct 1 ms 336 KB Output is correct
80 Correct 2 ms 296 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 212 KB Output is correct
83 Correct 1 ms 300 KB Output is correct
84 Correct 4 ms 440 KB Output is correct
85 Correct 8 ms 440 KB Output is correct
86 Correct 5 ms 444 KB Output is correct
87 Correct 5 ms 440 KB Output is correct
88 Correct 4 ms 516 KB Output is correct
89 Correct 6 ms 396 KB Output is correct
90 Correct 18 ms 2324 KB Output is correct
91 Correct 15 ms 2376 KB Output is correct
92 Correct 18 ms 2364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 1 ms 228 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 284 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 2 ms 304 KB Output is correct
22 Correct 2 ms 216 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 13 ms 1644 KB Output is correct
25 Correct 12 ms 1620 KB Output is correct
26 Correct 11 ms 1676 KB Output is correct
27 Correct 3 ms 824 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 3 ms 692 KB Output is correct
30 Correct 2 ms 440 KB Output is correct
31 Correct 2 ms 480 KB Output is correct
32 Correct 4 ms 436 KB Output is correct
33 Correct 697 ms 1328 KB Output is correct
34 Correct 679 ms 1316 KB Output is correct
35 Correct 671 ms 1364 KB Output is correct
36 Correct 674 ms 1328 KB Output is correct
37 Correct 695 ms 1348 KB Output is correct
38 Correct 680 ms 1356 KB Output is correct
39 Correct 994 ms 2088 KB Output is correct
40 Correct 969 ms 2080 KB Output is correct
41 Correct 985 ms 2084 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 296 KB Output is correct
45 Correct 1 ms 304 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 360 KB Output is correct
60 Correct 1 ms 304 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 304 KB Output is correct
63 Correct 1 ms 304 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 2 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 2 ms 340 KB Output is correct
69 Correct 1 ms 304 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 2 ms 212 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 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 300 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 296 KB Output is correct
85 Correct 7 ms 372 KB Output is correct
86 Correct 4 ms 468 KB Output is correct
87 Correct 2 ms 460 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 3 ms 340 KB Output is correct
90 Correct 4 ms 340 KB Output is correct
91 Correct 12 ms 1736 KB Output is correct
92 Correct 11 ms 1924 KB Output is correct
93 Correct 11 ms 2124 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 2 ms 296 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 2 ms 212 KB Output is correct
98 Correct 1 ms 300 KB Output is correct
99 Correct 4 ms 440 KB Output is correct
100 Correct 8 ms 440 KB Output is correct
101 Correct 5 ms 444 KB Output is correct
102 Correct 5 ms 440 KB Output is correct
103 Correct 4 ms 516 KB Output is correct
104 Correct 6 ms 396 KB Output is correct
105 Correct 18 ms 2324 KB Output is correct
106 Correct 15 ms 2376 KB Output is correct
107 Correct 18 ms 2364 KB Output is correct
108 Correct 3 ms 852 KB Output is correct
109 Correct 40 ms 704 KB Output is correct
110 Correct 186 ms 476 KB Output is correct
111 Correct 152 ms 472 KB Output is correct
112 Correct 208 ms 520 KB Output is correct
113 Correct 152 ms 500 KB Output is correct
114 Correct 697 ms 1400 KB Output is correct
115 Correct 49 ms 1444 KB Output is correct
116 Correct 627 ms 1940 KB Output is correct
117 Correct 523 ms 1380 KB Output is correct
118 Correct 72 ms 1516 KB Output is correct
119 Correct 967 ms 1368 KB Output is correct
120 Correct 515 ms 1820 KB Output is correct
121 Correct 292 ms 964 KB Output is correct
122 Correct 237 ms 2068 KB Output is correct
123 Correct 119 ms 844 KB Output is correct
124 Correct 152 ms 2140 KB Output is correct
125 Correct 88 ms 1072 KB Output is correct
126 Correct 24 ms 824 KB Output is correct
127 Correct 348 ms 960 KB Output is correct
128 Correct 96 ms 744 KB Output is correct
129 Correct 122 ms 780 KB Output is correct
130 Correct 3 ms 828 KB Output is correct
131 Correct 56 ms 940 KB Output is correct
132 Correct 304 ms 572 KB Output is correct
133 Correct 290 ms 596 KB Output is correct
134 Correct 299 ms 596 KB Output is correct
135 Correct 309 ms 596 KB Output is correct
136 Execution timed out 1571 ms 2004 KB Time limit exceeded
137 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 1 ms 228 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 284 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 2 ms 304 KB Output is correct
22 Correct 2 ms 216 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 13 ms 1644 KB Output is correct
25 Correct 12 ms 1620 KB Output is correct
26 Correct 11 ms 1676 KB Output is correct
27 Correct 3 ms 824 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 3 ms 692 KB Output is correct
30 Correct 2 ms 440 KB Output is correct
31 Correct 2 ms 480 KB Output is correct
32 Correct 4 ms 436 KB Output is correct
33 Correct 697 ms 1328 KB Output is correct
34 Correct 679 ms 1316 KB Output is correct
35 Correct 671 ms 1364 KB Output is correct
36 Correct 674 ms 1328 KB Output is correct
37 Correct 695 ms 1348 KB Output is correct
38 Correct 680 ms 1356 KB Output is correct
39 Correct 994 ms 2088 KB Output is correct
40 Correct 969 ms 2080 KB Output is correct
41 Correct 985 ms 2084 KB Output is correct
42 Correct 13 ms 2628 KB Output is correct
43 Correct 9 ms 1752 KB Output is correct
44 Correct 17 ms 1800 KB Output is correct
45 Correct 7 ms 1012 KB Output is correct
46 Correct 8 ms 900 KB Output is correct
47 Correct 13 ms 1236 KB Output is correct
48 Execution timed out 1556 ms 7800 KB Time limit exceeded
49 Halted 0 ms 0 KB -