답안 #571687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571687 2022-06-02T14:22:04 Z SlavicG 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 38988 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int K = 18;

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
    vector<int> p[k + 1];
    set<int> st[2 * n + 5][K];
    map<pair<int, int>, bool> mp;
    for(int i = 0; i < m; ++i) {
        for(auto x: b[i]) {
            p[x].pb(i);
            mp[{i, x}] = 1;
        }
    }

    /*
    for(int i = 0; i < n; ++i) {
        for(auto x: p[c[i]]) {
            st[i][0].insert(x);
        }
    }

    for(int j = 1; j < K; ++j) {
        for(int i = 0; i + (1 << j) <= n; ++i) {
            for(auto x: st[i][j - 1]) {
                if(st[i + (1 << j)][j - 1].count((x + (1 << j)) % m)) {    
                    st[i][j].insert(x);
                }
            }
        }
    }
    */
    vector<bool> can(n, false);

    for(int i = 0; i + m - 1 < n; ++i) {
        for(auto x: p[c[i]]) {
            int cur = x;
            int idx = i;
            bool ok = true;
            for(int j = K - 1; j >= 0; --j) {
                if(m & (1 << j)) {
                    if(!st[idx][j].count(cur)) {
                        ok = false;
                        break;
                    }
                    cur = (cur + (1 << j)) % m;
                    idx += (1 << j);
                    assert(idx <= n);
                }
            }
            if(ok) {
                assert(idx == i + m);
                can[i] = true;
                break;
            }
        }
    }


    for(int i = 0; i + m - 1 < n; ++i) {
        for(int x: p[c[i]]) {
            bool ok = true;
            for(int times = 0; times < m && ok; ++times) {
                if(!mp[{(x + times) % m, c[i + times]}]) ok = false;
            }
            if(ok) {
                can[i] = true;
                break;
            }
        }
    }

    set<int> good;
    forn(i, n) if(can[i]) good.insert(i); 
    int lst = -1e9, ans = 0;
    for(int i = 0; i < n; ++i) {
        if(lst + m - 1 >= i) continue;
        ++ans;
        if(can[i]) {
            lst = i;
        } else {
            auto it = good.lower_bound(i);
            if(it == good.begin()) return -1;
            --it;
            if(*it + m - 1 < i) return -1;
            lst = *it;
        }
    }
    return ans;
}

/*

void solve() {  
    
} 
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}   
*/
# 결과 실행 시간 메모리 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 256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1068 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1068 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 4 ms 3504 KB Output is correct
14 Correct 3 ms 3540 KB Output is correct
15 Correct 4 ms 3540 KB Output is correct
16 Correct 4 ms 3540 KB Output is correct
17 Correct 4 ms 3540 KB Output is correct
18 Correct 4 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3512 KB Output is correct
21 Correct 3 ms 3540 KB Output is correct
22 Correct 55 ms 14220 KB Output is correct
23 Correct 62 ms 14144 KB Output is correct
24 Correct 52 ms 14176 KB Output is correct
25 Correct 32 ms 35148 KB Output is correct
26 Correct 28 ms 35156 KB Output is correct
27 Correct 25 ms 34684 KB Output is correct
28 Correct 27 ms 34316 KB Output is correct
29 Correct 23 ms 34308 KB Output is correct
30 Correct 24 ms 34228 KB Output is correct
31 Execution timed out 1552 ms 38988 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1068 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1068 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 4 ms 3504 KB Output is correct
14 Correct 3 ms 3540 KB Output is correct
15 Correct 4 ms 3540 KB Output is correct
16 Correct 4 ms 3540 KB Output is correct
17 Correct 4 ms 3540 KB Output is correct
18 Correct 4 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3512 KB Output is correct
21 Correct 3 ms 3540 KB Output is correct
22 Correct 0 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 0 ms 212 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 3 ms 3044 KB Output is correct
34 Correct 3 ms 2612 KB Output is correct
35 Correct 2 ms 2132 KB Output is correct
36 Correct 3 ms 3244 KB Output is correct
37 Correct 3 ms 2736 KB Output is correct
38 Correct 2 ms 2900 KB Output is correct
39 Correct 1 ms 852 KB Output is correct
40 Correct 4 ms 2644 KB Output is correct
41 Correct 1 ms 852 KB Output is correct
42 Correct 2 ms 3284 KB Output is correct
43 Correct 3 ms 3028 KB Output is correct
44 Correct 1 ms 1108 KB Output is correct
45 Correct 1 ms 1108 KB Output is correct
46 Correct 2 ms 1108 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 3 ms 3540 KB Output is correct
51 Correct 4 ms 3540 KB Output is correct
52 Correct 4 ms 3540 KB Output is correct
53 Correct 4 ms 3540 KB Output is correct
54 Correct 5 ms 3540 KB Output is correct
55 Correct 4 ms 3540 KB Output is correct
56 Correct 3 ms 3540 KB Output is correct
57 Correct 3 ms 1236 KB Output is correct
58 Correct 3 ms 3540 KB Output is correct
59 Correct 3 ms 1236 KB Output is correct
60 Correct 2 ms 3540 KB Output is correct
61 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1068 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1068 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 4 ms 3504 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 4 ms 3540 KB Output is correct
18 Correct 4 ms 3540 KB Output is correct
19 Correct 4 ms 3540 KB Output is correct
20 Correct 4 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3512 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 55 ms 14220 KB Output is correct
25 Correct 62 ms 14144 KB Output is correct
26 Correct 52 ms 14176 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 852 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 852 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
36 Correct 3 ms 3044 KB Output is correct
37 Correct 3 ms 2612 KB Output is correct
38 Correct 2 ms 2132 KB Output is correct
39 Correct 3 ms 3244 KB Output is correct
40 Correct 3 ms 2736 KB Output is correct
41 Correct 2 ms 2900 KB Output is correct
42 Correct 1 ms 852 KB Output is correct
43 Correct 4 ms 2644 KB Output is correct
44 Correct 1 ms 852 KB Output is correct
45 Correct 2 ms 3284 KB Output is correct
46 Correct 3 ms 3028 KB Output is correct
47 Correct 1 ms 1108 KB Output is correct
48 Correct 1 ms 1108 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 2 ms 1108 KB Output is correct
53 Correct 3 ms 3540 KB Output is correct
54 Correct 4 ms 3540 KB Output is correct
55 Correct 4 ms 3540 KB Output is correct
56 Correct 4 ms 3540 KB Output is correct
57 Correct 5 ms 3540 KB Output is correct
58 Correct 4 ms 3540 KB Output is correct
59 Correct 3 ms 3540 KB Output is correct
60 Correct 3 ms 1236 KB Output is correct
61 Correct 3 ms 3540 KB Output is correct
62 Correct 3 ms 1236 KB Output is correct
63 Correct 2 ms 3540 KB Output is correct
64 Correct 3 ms 1236 KB Output is correct
65 Correct 1 ms 724 KB Output is correct
66 Correct 1 ms 1108 KB Output is correct
67 Correct 3 ms 1108 KB Output is correct
68 Correct 3 ms 1108 KB Output is correct
69 Correct 3 ms 1108 KB Output is correct
70 Correct 24 ms 3892 KB Output is correct
71 Correct 16 ms 3648 KB Output is correct
72 Correct 9 ms 3320 KB Output is correct
73 Correct 5 ms 3028 KB Output is correct
74 Correct 9 ms 3576 KB Output is correct
75 Correct 15 ms 3812 KB Output is correct
76 Correct 47 ms 12724 KB Output is correct
77 Correct 50 ms 14368 KB Output is correct
78 Correct 61 ms 16448 KB Output is correct
79 Correct 3 ms 1108 KB Output is correct
80 Correct 3 ms 1192 KB Output is correct
81 Correct 4 ms 1108 KB Output is correct
82 Correct 4 ms 1196 KB Output is correct
83 Correct 5 ms 1236 KB Output is correct
84 Correct 18 ms 4696 KB Output is correct
85 Correct 31 ms 4688 KB Output is correct
86 Correct 28 ms 4680 KB Output is correct
87 Correct 25 ms 4676 KB Output is correct
88 Correct 21 ms 4688 KB Output is correct
89 Correct 23 ms 4664 KB Output is correct
90 Correct 70 ms 17924 KB Output is correct
91 Correct 74 ms 17916 KB Output is correct
92 Correct 87 ms 17956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1068 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1068 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 4 ms 3504 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 4 ms 3540 KB Output is correct
18 Correct 4 ms 3540 KB Output is correct
19 Correct 4 ms 3540 KB Output is correct
20 Correct 4 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3512 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 55 ms 14220 KB Output is correct
25 Correct 62 ms 14144 KB Output is correct
26 Correct 52 ms 14176 KB Output is correct
27 Correct 32 ms 35148 KB Output is correct
28 Correct 28 ms 35156 KB Output is correct
29 Correct 25 ms 34684 KB Output is correct
30 Correct 27 ms 34316 KB Output is correct
31 Correct 23 ms 34308 KB Output is correct
32 Correct 24 ms 34228 KB Output is correct
33 Execution timed out 1552 ms 38988 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1068 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1068 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 4 ms 3504 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 4 ms 3540 KB Output is correct
18 Correct 4 ms 3540 KB Output is correct
19 Correct 4 ms 3540 KB Output is correct
20 Correct 4 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3512 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 55 ms 14220 KB Output is correct
25 Correct 62 ms 14144 KB Output is correct
26 Correct 52 ms 14176 KB Output is correct
27 Correct 32 ms 35148 KB Output is correct
28 Correct 28 ms 35156 KB Output is correct
29 Correct 25 ms 34684 KB Output is correct
30 Correct 27 ms 34316 KB Output is correct
31 Correct 23 ms 34308 KB Output is correct
32 Correct 24 ms 34228 KB Output is correct
33 Execution timed out 1552 ms 38988 KB Time limit exceeded
34 Halted 0 ms 0 KB -