답안 #737598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737598 2023-05-07T12:20:04 Z Abrar_Al_Samit 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 63772 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;



const int nax = 1e5 + 3;

vector<int>cand[nax], col_to_wall[nax];
bool good[nax];
int tag[nax];
int curtag = 1;
int vis[nax];
int to[nax];


// void dfs(int v) {
//     if(vis[v]==2) return;
//     if(vis[v]==1) {
//         ans = min(ans, curtag - tag[v]);
//         return;
//     }
//     vis[v] = 1;
//     tag[v] = curtag++;
//     dfs(to[v]);
//     vis[v] = 2;
// }
int minimumInstructions(
    int N, int M, int K, vector<int> C,
    vector<int> A, vector<vector<int>> B) {

    
    for(int i=0; i<N; ++i) {
        col_to_wall[C[i]].push_back(i);
    }

    for(int i=0; i<M; ++i) {
        for(int j=0; j<A[i]; ++j) {
            for(int x : col_to_wall[B[i][j]]) {
                cand[x].push_back(i);
            }
        }
    }

    for(int i=0; i<N; ++i) {
        sort(cand[i].begin(), cand[i].end());
    }

    // for(int i=0; i<N; ++i) {
    //     for(int j : cand[i]) {
    //         cerr<<j<< ' '; 
    //     }
    //     cerr<<'\n';
    // }

    for(int i=0; i<=N-M; ++i) {
        for(int j : cand[i]) {

            bool yasss = true;
            for(int l=0; l<M; ++l) {
                yasss &= binary_search(cand[i+l].begin(), 
                    cand[i+l].end(), (j+l)%M);
            }
            good[i] |= yasss;
        }
    }
    // for(int i=0; i<N; ++i) {
    //     cerr<<good[i]<<' ';
    // }
    // cerr<<'\n';


    if(!good[0]) return -1;
    int last = 0, pending = -1;

    int ans = 1;
    for(int i=1; i<N; ++i) {
        if(good[i]) {
            pending = i;
        }
        if(last+M==i) {
            if(pending==-1) return -1;
            last = pending;
            pending = -1;
            ++ans;
        }
    }
    return ans;



    // queue<int>q;
    // for(int i=M-1; i>=0; --i) {
    //     if(good[i]) {
    //         q.push(i);
    //     }
    // }
    // for(int i=N-1; i>=0; --i) {
    //     if(!q.empty()) {
    //         if((i+M)%N<q.front() || ((i+M)==N-1 && q.front()==0)) {
    //             q.pop();
    //         }
    //     }
    //     if(good[i]) {
    //         if(!q.empty()) {
    //             to[i] = q.front();
    //         } 
    //     }
    // }

    // for(int i=0; i<N; ++i) {
    //     cerr<<good[i]<<' ';
    // }
    // cerr<<'\n';

    // for(int i=0; i<N; ++i) if(good[i] && !tag[i]) {
    //     dfs(i);
    // }
    // if(ans==1e9) ans = -1;
    // return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 5008 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 5060 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Correct 4 ms 5016 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 14 ms 6332 KB Output is correct
23 Correct 13 ms 6408 KB Output is correct
24 Correct 12 ms 6300 KB Output is correct
25 Correct 6 ms 5916 KB Output is correct
26 Correct 6 ms 5844 KB Output is correct
27 Correct 6 ms 5844 KB Output is correct
28 Correct 8 ms 5844 KB Output is correct
29 Correct 7 ms 5912 KB Output is correct
30 Correct 7 ms 5912 KB Output is correct
31 Correct 183 ms 6948 KB Output is correct
32 Correct 180 ms 6948 KB Output is correct
33 Correct 184 ms 6936 KB Output is correct
34 Correct 179 ms 7072 KB Output is correct
35 Correct 189 ms 6940 KB Output is correct
36 Correct 178 ms 7064 KB Output is correct
37 Correct 262 ms 8052 KB Output is correct
38 Correct 275 ms 7980 KB Output is correct
39 Correct 255 ms 7996 KB Output is correct
40 Correct 16 ms 9100 KB Output is correct
41 Correct 10 ms 7576 KB Output is correct
42 Correct 17 ms 9492 KB Output is correct
43 Correct 13 ms 7960 KB Output is correct
44 Correct 12 ms 7764 KB Output is correct
45 Correct 20 ms 9684 KB Output is correct
46 Execution timed out 1570 ms 17884 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 5008 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5012 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 5060 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 5012 KB Output is correct
18 Correct 4 ms 5016 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 5 ms 5136 KB Output is correct
29 Correct 5 ms 5008 KB Output is correct
30 Correct 5 ms 4952 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 5 ms 4948 KB Output is correct
33 Correct 3 ms 5004 KB Output is correct
34 Correct 3 ms 4992 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 3 ms 5008 KB Output is correct
42 Correct 3 ms 5012 KB Output is correct
43 Correct 3 ms 5008 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 6 ms 5076 KB Output is correct
46 Correct 8 ms 5076 KB Output is correct
47 Correct 9 ms 5076 KB Output is correct
48 Correct 9 ms 5076 KB Output is correct
49 Correct 8 ms 5084 KB Output is correct
50 Correct 3 ms 5012 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 5012 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 3 ms 4948 KB Output is correct
58 Correct 3 ms 4948 KB Output is correct
59 Correct 4 ms 4948 KB Output is correct
60 Correct 3 ms 5016 KB Output is correct
61 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 5060 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5016 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 14 ms 6332 KB Output is correct
25 Correct 13 ms 6408 KB Output is correct
26 Correct 12 ms 6300 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 5 ms 5136 KB Output is correct
32 Correct 5 ms 5008 KB Output is correct
33 Correct 5 ms 4952 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 5 ms 4948 KB Output is correct
36 Correct 3 ms 5004 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 3 ms 5008 KB Output is correct
45 Correct 3 ms 5012 KB Output is correct
46 Correct 3 ms 5008 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 6 ms 5076 KB Output is correct
49 Correct 8 ms 5076 KB Output is correct
50 Correct 9 ms 5076 KB Output is correct
51 Correct 9 ms 5076 KB Output is correct
52 Correct 8 ms 5084 KB Output is correct
53 Correct 3 ms 5012 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 5012 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5076 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 3 ms 4948 KB Output is correct
62 Correct 4 ms 4948 KB Output is correct
63 Correct 3 ms 5016 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 34 ms 5204 KB Output is correct
66 Correct 9 ms 5076 KB Output is correct
67 Correct 62 ms 5204 KB Output is correct
68 Correct 23 ms 5300 KB Output is correct
69 Correct 50 ms 5256 KB Output is correct
70 Correct 13 ms 5204 KB Output is correct
71 Correct 14 ms 5264 KB Output is correct
72 Correct 11 ms 5204 KB Output is correct
73 Correct 4 ms 5140 KB Output is correct
74 Correct 12 ms 5148 KB Output is correct
75 Correct 9 ms 5204 KB Output is correct
76 Correct 15 ms 6492 KB Output is correct
77 Correct 15 ms 6684 KB Output is correct
78 Correct 18 ms 6996 KB Output is correct
79 Correct 139 ms 5520 KB Output is correct
80 Correct 133 ms 5548 KB Output is correct
81 Correct 153 ms 5460 KB Output is correct
82 Correct 145 ms 5460 KB Output is correct
83 Correct 137 ms 5544 KB Output is correct
84 Correct 18 ms 5332 KB Output is correct
85 Correct 20 ms 5276 KB Output is correct
86 Correct 20 ms 5280 KB Output is correct
87 Correct 19 ms 5332 KB Output is correct
88 Correct 19 ms 5360 KB Output is correct
89 Correct 20 ms 5332 KB Output is correct
90 Correct 18 ms 7112 KB Output is correct
91 Correct 18 ms 7064 KB Output is correct
92 Correct 19 ms 7156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 5060 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5016 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 14 ms 6332 KB Output is correct
25 Correct 13 ms 6408 KB Output is correct
26 Correct 12 ms 6300 KB Output is correct
27 Correct 6 ms 5916 KB Output is correct
28 Correct 6 ms 5844 KB Output is correct
29 Correct 6 ms 5844 KB Output is correct
30 Correct 8 ms 5844 KB Output is correct
31 Correct 7 ms 5912 KB Output is correct
32 Correct 7 ms 5912 KB Output is correct
33 Correct 183 ms 6948 KB Output is correct
34 Correct 180 ms 6948 KB Output is correct
35 Correct 184 ms 6936 KB Output is correct
36 Correct 179 ms 7072 KB Output is correct
37 Correct 189 ms 6940 KB Output is correct
38 Correct 178 ms 7064 KB Output is correct
39 Correct 262 ms 8052 KB Output is correct
40 Correct 275 ms 7980 KB Output is correct
41 Correct 255 ms 7996 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 5 ms 5136 KB Output is correct
47 Correct 5 ms 5008 KB Output is correct
48 Correct 5 ms 4952 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 5 ms 4948 KB Output is correct
51 Correct 3 ms 5004 KB Output is correct
52 Correct 3 ms 4992 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 3 ms 4948 KB Output is correct
58 Correct 4 ms 4948 KB Output is correct
59 Correct 3 ms 5008 KB Output is correct
60 Correct 3 ms 5012 KB Output is correct
61 Correct 3 ms 5008 KB Output is correct
62 Correct 3 ms 4948 KB Output is correct
63 Correct 6 ms 5076 KB Output is correct
64 Correct 8 ms 5076 KB Output is correct
65 Correct 9 ms 5076 KB Output is correct
66 Correct 9 ms 5076 KB Output is correct
67 Correct 8 ms 5084 KB Output is correct
68 Correct 3 ms 5012 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 5012 KB Output is correct
71 Correct 3 ms 5076 KB Output is correct
72 Correct 3 ms 5076 KB Output is correct
73 Correct 3 ms 5076 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 4 ms 4948 KB Output is correct
78 Correct 3 ms 5016 KB Output is correct
79 Correct 3 ms 4948 KB Output is correct
80 Correct 34 ms 5204 KB Output is correct
81 Correct 9 ms 5076 KB Output is correct
82 Correct 62 ms 5204 KB Output is correct
83 Correct 23 ms 5300 KB Output is correct
84 Correct 50 ms 5256 KB Output is correct
85 Correct 13 ms 5204 KB Output is correct
86 Correct 14 ms 5264 KB Output is correct
87 Correct 11 ms 5204 KB Output is correct
88 Correct 4 ms 5140 KB Output is correct
89 Correct 12 ms 5148 KB Output is correct
90 Correct 9 ms 5204 KB Output is correct
91 Correct 15 ms 6492 KB Output is correct
92 Correct 15 ms 6684 KB Output is correct
93 Correct 18 ms 6996 KB Output is correct
94 Correct 139 ms 5520 KB Output is correct
95 Correct 133 ms 5548 KB Output is correct
96 Correct 153 ms 5460 KB Output is correct
97 Correct 145 ms 5460 KB Output is correct
98 Correct 137 ms 5544 KB Output is correct
99 Correct 18 ms 5332 KB Output is correct
100 Correct 20 ms 5276 KB Output is correct
101 Correct 20 ms 5280 KB Output is correct
102 Correct 19 ms 5332 KB Output is correct
103 Correct 19 ms 5360 KB Output is correct
104 Correct 20 ms 5332 KB Output is correct
105 Correct 18 ms 7112 KB Output is correct
106 Correct 18 ms 7064 KB Output is correct
107 Correct 19 ms 7156 KB Output is correct
108 Correct 7 ms 5844 KB Output is correct
109 Execution timed out 1580 ms 63772 KB Time limit exceeded
110 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 5008 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 5060 KB Output is correct
16 Correct 3 ms 5008 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 5016 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5016 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 14 ms 6332 KB Output is correct
25 Correct 13 ms 6408 KB Output is correct
26 Correct 12 ms 6300 KB Output is correct
27 Correct 6 ms 5916 KB Output is correct
28 Correct 6 ms 5844 KB Output is correct
29 Correct 6 ms 5844 KB Output is correct
30 Correct 8 ms 5844 KB Output is correct
31 Correct 7 ms 5912 KB Output is correct
32 Correct 7 ms 5912 KB Output is correct
33 Correct 183 ms 6948 KB Output is correct
34 Correct 180 ms 6948 KB Output is correct
35 Correct 184 ms 6936 KB Output is correct
36 Correct 179 ms 7072 KB Output is correct
37 Correct 189 ms 6940 KB Output is correct
38 Correct 178 ms 7064 KB Output is correct
39 Correct 262 ms 8052 KB Output is correct
40 Correct 275 ms 7980 KB Output is correct
41 Correct 255 ms 7996 KB Output is correct
42 Correct 16 ms 9100 KB Output is correct
43 Correct 10 ms 7576 KB Output is correct
44 Correct 17 ms 9492 KB Output is correct
45 Correct 13 ms 7960 KB Output is correct
46 Correct 12 ms 7764 KB Output is correct
47 Correct 20 ms 9684 KB Output is correct
48 Execution timed out 1570 ms 17884 KB Time limit exceeded
49 Halted 0 ms 0 KB -