Submission #1077370

# Submission time Handle Problem Language Result Execution time Memory
1077370 2024-08-27T06:18:33 Z GrindMachine Painting Walls (APIO20_paint) C++17
28 / 100
1500 ms 7696 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define conts continue
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define ff first
#define ss second

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &x, T y){
    x = min(x,y);
}

template<typename T>
void amax(T &x, T y){
    x = max(x,y);
}

template<typename A,typename B>
string to_string(pair<A,B> p);

string to_string(const string &s){
    return "'"+s+"'";
}

string to_string(const char* s){
    return to_string((string)s);
}

string to_string(bool b){
    return b?"true":"false";
}

string to_string(vector<bool> v){
    string res = "{";
    rep(i,sz(v)){
        res += to_string(v[i])+",";
    }
    if(res.back() == ',') res.pop_back();
    res += "}";
    return res;
}

template<typename A>
string to_string(A v){
    string res = "{";
    trav(x,v){
        res += to_string(x)+",";
    }
    if(res.back() == ',') res.pop_back();
    res += "}";
    return res;
}

template<typename A,typename B>
string to_string(pair<A,B> p){
    return "("+to_string(p.ff)+","+to_string(p.ss)+")";
}

#define debug(x) cout << "[" << #x << "]: "; cout << to_string(x) << endl

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;

#include "paint.h"

int minimumInstructions(
    int n, int m, int k, std::vector<int> a,
    std::vector<int> sizes, std::vector<std::vector<int>> b) {

    vector<bool> can(n);

    rep(i,n){
        if(i+m-1 >= n) break;
        rep(x,m){
            bool ok = true;
            rep(l,m){
                int j = (x+l)%m;
                if(!binary_search(all(b[j]),a[i+l])){
                    ok = false;
                    break;
                }
            }

            if(ok){
                can[i] = 1;
                break;
            }
        }
    }

    vector<int> bef(n,-1);
    rep(i,n){
        if(i) bef[i] = bef[i-1];
        if(can[i]) bef[i] = i;
    }

    if(!can[0]){
        return -1;
    }

    int pos = 0;
    int ans = 1;

    while(pos+m < n){
        int nxt = bef[pos+m];
        if(nxt == pos) return -1;
        pos = nxt;
        ans++;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 10 ms 1628 KB Output is correct
23 Correct 10 ms 1628 KB Output is correct
24 Correct 9 ms 1628 KB Output is correct
25 Correct 2 ms 556 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 704 KB Output is correct
31 Correct 423 ms 1116 KB Output is correct
32 Correct 445 ms 1116 KB Output is correct
33 Correct 441 ms 1116 KB Output is correct
34 Correct 422 ms 1360 KB Output is correct
35 Correct 443 ms 1116 KB Output is correct
36 Correct 422 ms 1116 KB Output is correct
37 Correct 816 ms 2228 KB Output is correct
38 Correct 814 ms 2216 KB Output is correct
39 Correct 820 ms 2212 KB Output is correct
40 Correct 6 ms 1624 KB Output is correct
41 Correct 5 ms 1116 KB Output is correct
42 Correct 9 ms 1628 KB Output is correct
43 Correct 5 ms 1116 KB Output is correct
44 Correct 5 ms 1056 KB Output is correct
45 Correct 8 ms 1628 KB Output is correct
46 Execution timed out 1598 ms 7696 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 440 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 688 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 10 ms 1628 KB Output is correct
25 Correct 10 ms 1628 KB Output is correct
26 Correct 9 ms 1628 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 440 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 688 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 2 ms 344 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 1 ms 432 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 3 ms 600 KB Output is correct
71 Correct 3 ms 528 KB Output is correct
72 Correct 2 ms 348 KB Output is correct
73 Correct 1 ms 452 KB Output is correct
74 Correct 2 ms 600 KB Output is correct
75 Correct 2 ms 348 KB Output is correct
76 Correct 9 ms 1828 KB Output is correct
77 Correct 9 ms 1884 KB Output is correct
78 Correct 13 ms 2148 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 3 ms 604 KB Output is correct
85 Correct 4 ms 604 KB Output is correct
86 Correct 4 ms 604 KB Output is correct
87 Correct 4 ms 604 KB Output is correct
88 Correct 3 ms 644 KB Output is correct
89 Correct 3 ms 604 KB Output is correct
90 Correct 13 ms 2396 KB Output is correct
91 Correct 13 ms 2576 KB Output is correct
92 Correct 14 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 10 ms 1628 KB Output is correct
25 Correct 10 ms 1628 KB Output is correct
26 Correct 9 ms 1628 KB Output is correct
27 Correct 2 ms 556 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 704 KB Output is correct
33 Correct 423 ms 1116 KB Output is correct
34 Correct 445 ms 1116 KB Output is correct
35 Correct 441 ms 1116 KB Output is correct
36 Correct 422 ms 1360 KB Output is correct
37 Correct 443 ms 1116 KB Output is correct
38 Correct 422 ms 1116 KB Output is correct
39 Correct 816 ms 2228 KB Output is correct
40 Correct 814 ms 2216 KB Output is correct
41 Correct 820 ms 2212 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 440 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 1 ms 688 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 2 ms 344 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 344 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 1 ms 432 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 3 ms 600 KB Output is correct
86 Correct 3 ms 528 KB Output is correct
87 Correct 2 ms 348 KB Output is correct
88 Correct 1 ms 452 KB Output is correct
89 Correct 2 ms 600 KB Output is correct
90 Correct 2 ms 348 KB Output is correct
91 Correct 9 ms 1828 KB Output is correct
92 Correct 9 ms 1884 KB Output is correct
93 Correct 13 ms 2148 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 1 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 1 ms 348 KB Output is correct
99 Correct 3 ms 604 KB Output is correct
100 Correct 4 ms 604 KB Output is correct
101 Correct 4 ms 604 KB Output is correct
102 Correct 4 ms 604 KB Output is correct
103 Correct 3 ms 644 KB Output is correct
104 Correct 3 ms 604 KB Output is correct
105 Correct 13 ms 2396 KB Output is correct
106 Correct 13 ms 2576 KB Output is correct
107 Correct 14 ms 2396 KB Output is correct
108 Correct 2 ms 600 KB Output is correct
109 Correct 21 ms 644 KB Output is correct
110 Correct 125 ms 628 KB Output is correct
111 Correct 104 ms 600 KB Output is correct
112 Correct 140 ms 600 KB Output is correct
113 Correct 95 ms 600 KB Output is correct
114 Correct 432 ms 1368 KB Output is correct
115 Correct 42 ms 1384 KB Output is correct
116 Correct 359 ms 1628 KB Output is correct
117 Correct 240 ms 1364 KB Output is correct
118 Correct 59 ms 1440 KB Output is correct
119 Correct 491 ms 1332 KB Output is correct
120 Correct 437 ms 1948 KB Output is correct
121 Correct 196 ms 876 KB Output is correct
122 Correct 204 ms 2140 KB Output is correct
123 Correct 87 ms 604 KB Output is correct
124 Correct 135 ms 2392 KB Output is correct
125 Correct 69 ms 952 KB Output is correct
126 Correct 20 ms 860 KB Output is correct
127 Correct 268 ms 1152 KB Output is correct
128 Correct 70 ms 876 KB Output is correct
129 Correct 94 ms 856 KB Output is correct
130 Correct 2 ms 604 KB Output is correct
131 Correct 29 ms 704 KB Output is correct
132 Correct 205 ms 604 KB Output is correct
133 Correct 203 ms 720 KB Output is correct
134 Correct 203 ms 604 KB Output is correct
135 Correct 203 ms 600 KB Output is correct
136 Correct 1310 ms 1952 KB Output is correct
137 Correct 1018 ms 1884 KB Output is correct
138 Execution timed out 1530 ms 1948 KB Time limit exceeded
139 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 10 ms 1628 KB Output is correct
25 Correct 10 ms 1628 KB Output is correct
26 Correct 9 ms 1628 KB Output is correct
27 Correct 2 ms 556 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 704 KB Output is correct
33 Correct 423 ms 1116 KB Output is correct
34 Correct 445 ms 1116 KB Output is correct
35 Correct 441 ms 1116 KB Output is correct
36 Correct 422 ms 1360 KB Output is correct
37 Correct 443 ms 1116 KB Output is correct
38 Correct 422 ms 1116 KB Output is correct
39 Correct 816 ms 2228 KB Output is correct
40 Correct 814 ms 2216 KB Output is correct
41 Correct 820 ms 2212 KB Output is correct
42 Correct 6 ms 1624 KB Output is correct
43 Correct 5 ms 1116 KB Output is correct
44 Correct 9 ms 1628 KB Output is correct
45 Correct 5 ms 1116 KB Output is correct
46 Correct 5 ms 1056 KB Output is correct
47 Correct 8 ms 1628 KB Output is correct
48 Execution timed out 1598 ms 7696 KB Time limit exceeded
49 Halted 0 ms 0 KB -