답안 #402036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402036 2021-05-11T08:30:57 Z Collypso 벽 칠하기 (APIO20_paint) C++17
12 / 100
88 ms 19144 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
//#define endl '\n'
//#define int long long

using namespace std;

bool exists(vt<int>& master, int m)
{
    auto it = lower_bound(all(master), m);
    if (it == master.end()) return 0;
    return (*it == m);
}

int minimumInstructions(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B)
{
    vt<vt<int>> master(K);
    for(int i = 0; i < M; i++)
        for(int j = 0; j < A[i]; j++) master[B[i][j]].pb(i);
    vt<vt<pair<int, int>>> dp(N);
    for(int m : master[C[0]]) dp[0].pb({m, 1});
    for(int i = 1; i < N; i++)
    {
        for(int m : master[C[i]])
        {
            int preM = (m + M - 1) % M, len = 1;
            auto it = lower_bound(all(dp[i - 1]), make_pair(preM, 0));
            if (it != dp[i - 1].end())
                if ((*it).first == preM) len = min(M, (*it).second + 1);
            dp[i].pb({m, len});
        }
    }
    int ans = 0, pos = -1;
    for(int i = M - 1, d = 1, flag = 0; i < N && d > 0; i++, d--)
    {
        //cout << i << " " << d << " " << pos << " " << flag << endl;
        for(auto m : dp[i]) m.second == M ? pos = i, flag = 1 : flag;
        if ((d == 1 || i == N - 1) && flag) ans++, d = M + 1, flag = 0;
    }
    if (pos == N - 1) return ans;
    return -1;
}

/**
main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    freopen("input.txt", "r", stdin);
    int N, M, K;
    cin >> N >> M >> K;
    vt<int> C(N), A(M);
    vt<vt<int>> B(M);
    for(int i = 0; i < N; i++) cin >> C[i];
    for(int i = 0; i < M; i++)
    {
        cin >> A[i];
        B[i].resize(A[i]);
        for(int j = 0; j < A[i]; j++) cin >> B[i][j];
    }

    //cout << M << endl;
    int ans = minimumInstructions(N, M, K, C, A, B);
    cout << ans << endl;

    //int ans = minimumInstructions(6, 4, 4, {2, 1, 0, 3, 2, 1}, {3}, {{2}, {1}, {0}, {3}});
    //cout << ans << endl;
}
/**/

Compilation message

paint.cpp:75:1: warning: "/*" within comment [-Wcomment]
   75 | /**/
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 25 ms 7116 KB Output is correct
23 Correct 25 ms 7108 KB Output is correct
24 Correct 25 ms 7148 KB Output is correct
25 Correct 4 ms 1484 KB Output is correct
26 Correct 4 ms 1484 KB Output is correct
27 Correct 5 ms 1484 KB Output is correct
28 Correct 5 ms 1580 KB Output is correct
29 Correct 5 ms 1484 KB Output is correct
30 Correct 5 ms 1580 KB Output is correct
31 Correct 12 ms 4940 KB Output is correct
32 Correct 12 ms 5056 KB Output is correct
33 Correct 12 ms 5040 KB Output is correct
34 Correct 12 ms 4940 KB Output is correct
35 Correct 13 ms 4940 KB Output is correct
36 Correct 12 ms 5040 KB Output is correct
37 Correct 32 ms 8608 KB Output is correct
38 Correct 31 ms 8652 KB Output is correct
39 Correct 33 ms 8664 KB Output is correct
40 Correct 17 ms 6112 KB Output is correct
41 Correct 11 ms 3916 KB Output is correct
42 Correct 25 ms 6636 KB Output is correct
43 Correct 14 ms 4428 KB Output is correct
44 Correct 15 ms 4108 KB Output is correct
45 Correct 22 ms 6648 KB Output is correct
46 Correct 60 ms 17592 KB Output is correct
47 Correct 39 ms 11120 KB Output is correct
48 Correct 41 ms 13480 KB Output is correct
49 Correct 58 ms 14080 KB Output is correct
50 Correct 58 ms 14396 KB Output is correct
51 Correct 47 ms 11844 KB Output is correct
52 Correct 19 ms 6648 KB Output is correct
53 Correct 21 ms 6648 KB Output is correct
54 Correct 20 ms 6720 KB Output is correct
55 Correct 21 ms 6720 KB Output is correct
56 Correct 20 ms 6664 KB Output is correct
57 Correct 20 ms 6688 KB Output is correct
58 Correct 66 ms 19144 KB Output is correct
59 Correct 67 ms 19132 KB Output is correct
60 Correct 68 ms 19116 KB Output is correct
61 Correct 64 ms 19124 KB Output is correct
62 Correct 65 ms 19140 KB Output is correct
63 Correct 88 ms 19140 KB Output is correct
64 Correct 76 ms 18336 KB Output is correct
65 Correct 75 ms 18344 KB Output is correct
66 Correct 71 ms 18240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 216 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 288 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 2 ms 2352 KB Output is correct
34 Correct 2 ms 1832 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2124 KB Output is correct
38 Correct 3 ms 2380 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 2 ms 2088 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 2508 KB Output is correct
43 Incorrect 3 ms 2380 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 25 ms 7116 KB Output is correct
25 Correct 25 ms 7108 KB Output is correct
26 Correct 25 ms 7148 KB Output is correct
27 Correct 1 ms 216 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 288 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 288 KB Output is correct
36 Correct 2 ms 2352 KB Output is correct
37 Correct 2 ms 1832 KB Output is correct
38 Correct 2 ms 1612 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 2 ms 2124 KB Output is correct
41 Correct 3 ms 2380 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 2 ms 2088 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 2 ms 2508 KB Output is correct
46 Incorrect 3 ms 2380 KB Output isn't correct
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 25 ms 7116 KB Output is correct
25 Correct 25 ms 7108 KB Output is correct
26 Correct 25 ms 7148 KB Output is correct
27 Correct 4 ms 1484 KB Output is correct
28 Correct 4 ms 1484 KB Output is correct
29 Correct 5 ms 1484 KB Output is correct
30 Correct 5 ms 1580 KB Output is correct
31 Correct 5 ms 1484 KB Output is correct
32 Correct 5 ms 1580 KB Output is correct
33 Correct 12 ms 4940 KB Output is correct
34 Correct 12 ms 5056 KB Output is correct
35 Correct 12 ms 5040 KB Output is correct
36 Correct 12 ms 4940 KB Output is correct
37 Correct 13 ms 4940 KB Output is correct
38 Correct 12 ms 5040 KB Output is correct
39 Correct 32 ms 8608 KB Output is correct
40 Correct 31 ms 8652 KB Output is correct
41 Correct 33 ms 8664 KB Output is correct
42 Correct 1 ms 216 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 288 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 288 KB Output is correct
51 Correct 2 ms 2352 KB Output is correct
52 Correct 2 ms 1832 KB Output is correct
53 Correct 2 ms 1612 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2124 KB Output is correct
56 Correct 3 ms 2380 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 2 ms 2088 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 2 ms 2508 KB Output is correct
61 Incorrect 3 ms 2380 KB Output isn't correct
62 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 25 ms 7116 KB Output is correct
25 Correct 25 ms 7108 KB Output is correct
26 Correct 25 ms 7148 KB Output is correct
27 Correct 4 ms 1484 KB Output is correct
28 Correct 4 ms 1484 KB Output is correct
29 Correct 5 ms 1484 KB Output is correct
30 Correct 5 ms 1580 KB Output is correct
31 Correct 5 ms 1484 KB Output is correct
32 Correct 5 ms 1580 KB Output is correct
33 Correct 12 ms 4940 KB Output is correct
34 Correct 12 ms 5056 KB Output is correct
35 Correct 12 ms 5040 KB Output is correct
36 Correct 12 ms 4940 KB Output is correct
37 Correct 13 ms 4940 KB Output is correct
38 Correct 12 ms 5040 KB Output is correct
39 Correct 32 ms 8608 KB Output is correct
40 Correct 31 ms 8652 KB Output is correct
41 Correct 33 ms 8664 KB Output is correct
42 Correct 17 ms 6112 KB Output is correct
43 Correct 11 ms 3916 KB Output is correct
44 Correct 25 ms 6636 KB Output is correct
45 Correct 14 ms 4428 KB Output is correct
46 Correct 15 ms 4108 KB Output is correct
47 Correct 22 ms 6648 KB Output is correct
48 Correct 60 ms 17592 KB Output is correct
49 Correct 39 ms 11120 KB Output is correct
50 Correct 41 ms 13480 KB Output is correct
51 Correct 58 ms 14080 KB Output is correct
52 Correct 58 ms 14396 KB Output is correct
53 Correct 47 ms 11844 KB Output is correct
54 Correct 19 ms 6648 KB Output is correct
55 Correct 21 ms 6648 KB Output is correct
56 Correct 20 ms 6720 KB Output is correct
57 Correct 21 ms 6720 KB Output is correct
58 Correct 20 ms 6664 KB Output is correct
59 Correct 20 ms 6688 KB Output is correct
60 Correct 66 ms 19144 KB Output is correct
61 Correct 67 ms 19132 KB Output is correct
62 Correct 68 ms 19116 KB Output is correct
63 Correct 64 ms 19124 KB Output is correct
64 Correct 65 ms 19140 KB Output is correct
65 Correct 88 ms 19140 KB Output is correct
66 Correct 76 ms 18336 KB Output is correct
67 Correct 75 ms 18344 KB Output is correct
68 Correct 71 ms 18240 KB Output is correct
69 Correct 1 ms 216 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 288 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 2 ms 332 KB Output is correct
76 Correct 1 ms 332 KB Output is correct
77 Correct 1 ms 288 KB Output is correct
78 Correct 2 ms 2352 KB Output is correct
79 Correct 2 ms 1832 KB Output is correct
80 Correct 2 ms 1612 KB Output is correct
81 Correct 2 ms 2636 KB Output is correct
82 Correct 2 ms 2124 KB Output is correct
83 Correct 3 ms 2380 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 2 ms 2088 KB Output is correct
86 Correct 1 ms 336 KB Output is correct
87 Correct 2 ms 2508 KB Output is correct
88 Incorrect 3 ms 2380 KB Output isn't correct
89 Halted 0 ms 0 KB -