답안 #752687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
752687 2023-06-03T12:24:01 Z benjaminkleyn 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 9768 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

struct section
{
    // used to store a segment of the wall which i know can be painted nicely.
    int x, y, cnt;
    // we can do this for 0 <= l < cnt, instead of just M.
};

bool operator<(const section &X, const section &Y)
{
    return X.y + X.cnt < Y.y + Y.cnt;
}

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
    vector<set<int>> b(M);
    for (int i = 0; i < M; i++)
        b[i] = set<int>(B[i].begin(), B[i].end());

    vector<section> sections1;
    for (int offset = 0; offset < M; offset++)
    {
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (b[(i + offset) % M].find(C[i]) == b[(i + offset) % M].end())
            {
                if (cnt >= M)
                    sections1.push_back({(i - cnt + offset) % M, i - cnt, cnt});
                cnt = 0;
            }
            else
                cnt++;
        }
        if (cnt >= M)
            sections1.push_back({(N - cnt + offset) % M, N - cnt, cnt});
    }

    sort(sections1.begin(), sections1.end(), [] (const section &X, const section &Y) { return X.y < Y.y; });

    vector<bool> done(N, false);
    int ans = 0;
    set<section> sections;
    int r = 0;
    for (int i = 0; i < N; i++)
    {
        while (r < sections1.size() && sections1[r].y == i)
            sections.insert(sections1[r++]);

        if (!done[i])
        {
            if (sections.size() == 0)
                return -1;
            auto [x, y, cnt] = *sections.rbegin();
            ans++;
            for (int j = i; j < N && j < y + cnt && j < i + M; j++)
                done[j] = true;
        }

        while (sections.begin()->y + sections.begin()->cnt - 1 == i)
            sections.erase(sections.begin());
    }
    
    return ans;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<section>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (r < sections1.size() && sections1[r].y == i)
      |                ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 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 304 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 312 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 312 KB Output is correct
20 Correct 3 ms 316 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 31 ms 6384 KB Output is correct
23 Correct 31 ms 6380 KB Output is correct
24 Correct 31 ms 6340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 3 ms 416 KB Output is correct
31 Correct 1172 ms 2124 KB Output is correct
32 Correct 1184 ms 2004 KB Output is correct
33 Correct 1172 ms 2004 KB Output is correct
34 Correct 1170 ms 1996 KB Output is correct
35 Correct 1182 ms 2004 KB Output is correct
36 Correct 1162 ms 2004 KB Output is correct
37 Execution timed out 1573 ms 6860 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 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 304 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 312 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 312 KB Output is correct
20 Correct 3 ms 316 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 300 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 308 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 304 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 340 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 2 ms 340 KB Output is correct
52 Correct 3 ms 308 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 3 ms 340 KB Output is correct
56 Correct 3 ms 312 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 4 ms 308 KB Output is correct
59 Correct 2 ms 340 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
61 Correct 3 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 300 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 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 3 ms 312 KB Output is correct
22 Correct 3 ms 316 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 31 ms 6384 KB Output is correct
25 Correct 31 ms 6380 KB Output is correct
26 Correct 31 ms 6340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 300 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 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 308 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 308 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 1 ms 304 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 300 KB Output is correct
50 Correct 1 ms 340 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 2 ms 340 KB Output is correct
55 Correct 3 ms 308 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 3 ms 340 KB Output is correct
59 Correct 3 ms 312 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 4 ms 308 KB Output is correct
62 Correct 2 ms 340 KB Output is correct
63 Correct 3 ms 340 KB Output is correct
64 Correct 3 ms 304 KB Output is correct
65 Correct 1 ms 308 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 308 KB Output is correct
70 Correct 7 ms 852 KB Output is correct
71 Correct 7 ms 980 KB Output is correct
72 Correct 7 ms 976 KB Output is correct
73 Correct 2 ms 572 KB Output is correct
74 Correct 5 ms 896 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 25 ms 7052 KB Output is correct
77 Correct 36 ms 7648 KB Output is correct
78 Correct 28 ms 9016 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 2 ms 300 KB Output is correct
82 Correct 2 ms 340 KB Output is correct
83 Correct 2 ms 340 KB Output is correct
84 Correct 9 ms 1080 KB Output is correct
85 Correct 10 ms 1192 KB Output is correct
86 Correct 9 ms 1176 KB Output is correct
87 Correct 9 ms 1188 KB Output is correct
88 Correct 9 ms 1180 KB Output is correct
89 Correct 9 ms 1088 KB Output is correct
90 Correct 45 ms 9720 KB Output is correct
91 Correct 44 ms 9732 KB Output is correct
92 Correct 52 ms 9768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 300 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 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 3 ms 312 KB Output is correct
22 Correct 3 ms 316 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 31 ms 6384 KB Output is correct
25 Correct 31 ms 6380 KB Output is correct
26 Correct 31 ms 6340 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 416 KB Output is correct
33 Correct 1172 ms 2124 KB Output is correct
34 Correct 1184 ms 2004 KB Output is correct
35 Correct 1172 ms 2004 KB Output is correct
36 Correct 1170 ms 1996 KB Output is correct
37 Correct 1182 ms 2004 KB Output is correct
38 Correct 1162 ms 2004 KB Output is correct
39 Execution timed out 1573 ms 6860 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 300 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 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 2 ms 304 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 3 ms 312 KB Output is correct
22 Correct 3 ms 316 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
24 Correct 31 ms 6384 KB Output is correct
25 Correct 31 ms 6380 KB Output is correct
26 Correct 31 ms 6340 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 416 KB Output is correct
33 Correct 1172 ms 2124 KB Output is correct
34 Correct 1184 ms 2004 KB Output is correct
35 Correct 1172 ms 2004 KB Output is correct
36 Correct 1170 ms 1996 KB Output is correct
37 Correct 1182 ms 2004 KB Output is correct
38 Correct 1162 ms 2004 KB Output is correct
39 Execution timed out 1573 ms 6860 KB Time limit exceeded
40 Halted 0 ms 0 KB -