Submission #892759

# Submission time Handle Problem Language Result Execution time Memory
892759 2023-12-25T21:58:22 Z betterdanjoe Painting Walls (APIO20_paint) C++17
12 / 100
63 ms 24808 KB
#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

template<class K> using sset =  tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll ceil0(ll a, ll b) {
    return a / b + ((a ^ b) > 0 && a % b);
}

void setIO() {
    ios_base::sync_with_stdio(0); cin.tie(0);
}

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
    vector<int> pos[K];
    for(int i = 0; i < N; i++){
        pos[C[i]].pb(i);
    }
    vector<int> val[N];
    vector<int> len[N];
    for(int i = 0; i < M; i++){
        for(int j : B[i]){
            for(int k : pos[j]){
                val[k].pb(i);
            }
        }
    }
    for(int i = 0; i < N; i++) len[i].resize(val[i].size(), 0);
    for(int i = N - 1; i >= 1; i--){
        for(int j = 0; j < val[i].size(); j++){
            int k = lower_bound(val[i - 1].begin(), val[i - 1].end(), val[i][j] - 1) - val[i - 1].begin();
            if(k == val[i - 1].size() || val[i - 1][k] != val[i][j] - 1) continue;
            len[i - 1][k] = len[i][j] + 1;
        }
    }
    bool check[N];
    memset(check, false, sizeof(check));
    for(int i = 0; i < N - M + 1; i++){
        for(int j = 0; j < val[i].size(); j++){
            if(len[i][j] == M - 1){
                check[i] = true;
                break;
            }
            if(len[i][j] == M - 1 - val[i][j] && val[i + len[i][j] + 1][0] == 0 && len[i + len[i][j] + 1][0] >= val[i][j] - 1){
                check[i] = true;
                break;
            }
        }
    }
    int cur = 0;
    int prv = 0;
    int ans = 0;
    while(cur < N){
        int nxt = -1;
        for(int i = prv; i <= cur; i++){
            if(check[i]) nxt = i + M;
        }
        if(nxt == -1) return -1;
        ans++;
        prv = cur + 1;
        cur = nxt;
    }
    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:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j = 0; j < val[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~
paint.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if(k == val[i - 1].size() || val[i - 1][k] != val[i][j] - 1) continue;
      |                ~~^~~~~~~~~~~~~~~~~~~~
paint.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j = 0; j < val[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 2744 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2740 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 9 ms 4228 KB Output is correct
23 Correct 9 ms 4184 KB Output is correct
24 Correct 9 ms 4024 KB Output is correct
25 Correct 4 ms 2908 KB Output is correct
26 Correct 4 ms 2852 KB Output is correct
27 Correct 4 ms 2904 KB Output is correct
28 Correct 5 ms 2904 KB Output is correct
29 Correct 4 ms 2908 KB Output is correct
30 Correct 4 ms 2908 KB Output is correct
31 Correct 9 ms 6236 KB Output is correct
32 Correct 9 ms 6204 KB Output is correct
33 Correct 9 ms 6236 KB Output is correct
34 Correct 9 ms 6268 KB Output is correct
35 Correct 9 ms 6236 KB Output is correct
36 Correct 13 ms 6176 KB Output is correct
37 Correct 16 ms 7416 KB Output is correct
38 Correct 15 ms 7164 KB Output is correct
39 Correct 15 ms 7260 KB Output is correct
40 Correct 18 ms 11476 KB Output is correct
41 Correct 12 ms 7384 KB Output is correct
42 Correct 20 ms 12676 KB Output is correct
43 Correct 13 ms 8540 KB Output is correct
44 Correct 12 ms 7772 KB Output is correct
45 Correct 20 ms 12892 KB Output is correct
46 Correct 43 ms 22336 KB Output is correct
47 Correct 26 ms 14268 KB Output is correct
48 Correct 37 ms 16728 KB Output is correct
49 Correct 43 ms 16212 KB Output is correct
50 Correct 38 ms 17232 KB Output is correct
51 Correct 34 ms 15232 KB Output is correct
52 Correct 20 ms 12844 KB Output is correct
53 Correct 19 ms 12752 KB Output is correct
54 Correct 20 ms 12724 KB Output is correct
55 Correct 22 ms 12728 KB Output is correct
56 Correct 22 ms 12776 KB Output is correct
57 Correct 22 ms 12888 KB Output is correct
58 Correct 63 ms 24764 KB Output is correct
59 Correct 48 ms 24660 KB Output is correct
60 Correct 47 ms 24808 KB Output is correct
61 Correct 47 ms 24660 KB Output is correct
62 Correct 50 ms 24752 KB Output is correct
63 Correct 47 ms 24656 KB Output is correct
64 Correct 53 ms 22864 KB Output is correct
65 Correct 52 ms 22864 KB Output is correct
66 Correct 56 ms 22704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 2744 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2740 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Runtime error 1 ms 348 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 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 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2744 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2740 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 9 ms 4228 KB Output is correct
25 Correct 9 ms 4184 KB Output is correct
26 Correct 9 ms 4024 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Runtime error 1 ms 348 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 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 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2744 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2740 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 9 ms 4228 KB Output is correct
25 Correct 9 ms 4184 KB Output is correct
26 Correct 9 ms 4024 KB Output is correct
27 Correct 4 ms 2908 KB Output is correct
28 Correct 4 ms 2852 KB Output is correct
29 Correct 4 ms 2904 KB Output is correct
30 Correct 5 ms 2904 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 4 ms 2908 KB Output is correct
33 Correct 9 ms 6236 KB Output is correct
34 Correct 9 ms 6204 KB Output is correct
35 Correct 9 ms 6236 KB Output is correct
36 Correct 9 ms 6268 KB Output is correct
37 Correct 9 ms 6236 KB Output is correct
38 Correct 13 ms 6176 KB Output is correct
39 Correct 16 ms 7416 KB Output is correct
40 Correct 15 ms 7164 KB Output is correct
41 Correct 15 ms 7260 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Runtime error 1 ms 348 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 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 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2744 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2740 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 9 ms 4228 KB Output is correct
25 Correct 9 ms 4184 KB Output is correct
26 Correct 9 ms 4024 KB Output is correct
27 Correct 4 ms 2908 KB Output is correct
28 Correct 4 ms 2852 KB Output is correct
29 Correct 4 ms 2904 KB Output is correct
30 Correct 5 ms 2904 KB Output is correct
31 Correct 4 ms 2908 KB Output is correct
32 Correct 4 ms 2908 KB Output is correct
33 Correct 9 ms 6236 KB Output is correct
34 Correct 9 ms 6204 KB Output is correct
35 Correct 9 ms 6236 KB Output is correct
36 Correct 9 ms 6268 KB Output is correct
37 Correct 9 ms 6236 KB Output is correct
38 Correct 13 ms 6176 KB Output is correct
39 Correct 16 ms 7416 KB Output is correct
40 Correct 15 ms 7164 KB Output is correct
41 Correct 15 ms 7260 KB Output is correct
42 Correct 18 ms 11476 KB Output is correct
43 Correct 12 ms 7384 KB Output is correct
44 Correct 20 ms 12676 KB Output is correct
45 Correct 13 ms 8540 KB Output is correct
46 Correct 12 ms 7772 KB Output is correct
47 Correct 20 ms 12892 KB Output is correct
48 Correct 43 ms 22336 KB Output is correct
49 Correct 26 ms 14268 KB Output is correct
50 Correct 37 ms 16728 KB Output is correct
51 Correct 43 ms 16212 KB Output is correct
52 Correct 38 ms 17232 KB Output is correct
53 Correct 34 ms 15232 KB Output is correct
54 Correct 20 ms 12844 KB Output is correct
55 Correct 19 ms 12752 KB Output is correct
56 Correct 20 ms 12724 KB Output is correct
57 Correct 22 ms 12728 KB Output is correct
58 Correct 22 ms 12776 KB Output is correct
59 Correct 22 ms 12888 KB Output is correct
60 Correct 63 ms 24764 KB Output is correct
61 Correct 48 ms 24660 KB Output is correct
62 Correct 47 ms 24808 KB Output is correct
63 Correct 47 ms 24660 KB Output is correct
64 Correct 50 ms 24752 KB Output is correct
65 Correct 47 ms 24656 KB Output is correct
66 Correct 53 ms 22864 KB Output is correct
67 Correct 52 ms 22864 KB Output is correct
68 Correct 56 ms 22704 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Runtime error 1 ms 348 KB Execution killed with signal 11
71 Halted 0 ms 0 KB -