답안 #999716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999716 2024-06-16T05:46:57 Z underwaterkillerwhale 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 318292 KB
#include "paint.h"

#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N  = 2e5 + 7;
const int Mod = 998244353;
const int szBL = 916;
const int INF = 1e9;
const int BASE = 137;
int n, m, K;

vector<int> A, C;
vector<vector<int>> B;

namespace sub4 {
    const int N2 = 20000 + 2;
    const int M2 = 2000 + 2;
    int dp[N2][M2 * 2], f[N];
    bool ok[N2];

    struct Segment_Tree {
        int Range;
        int st[N << 2];

        void init (int n) {
            Range = n;
            rep (i, 1, n << 2) {
                st[i] = INF;
            }
        }

        void update (int id, int l, int r, int pos, int val) {
            if (l > pos || r < pos) return;
            if (l == r) {
                st[id] = val;
                return;
            }
            int mid = l + r >> 1;
            update (id << 1, l, mid, pos, val);
            update (id << 1 | 1, mid + 1, r, pos, val);
            st[id] = min(st[id << 1], st[id << 1 | 1]);
        }
        int get (int id, int l, int r, int u, int v) {
            if (l > v || r < u) return INF;
            if (l >= u && r <= v) return st[id];
            int mid = l + r >> 1;
            return min (get (id << 1, l, mid, u, v), get (id << 1 | 1, mid + 1, r, u, v));
        }

        void update (int pos, int val ) {
            update (1, 1, Range, pos, val);
        }
        int get (int u, int v) {
            return get (1, 1, Range, u, v);
        }
    }ST;

    int solution() {
        A.resize (2 * m);
        B.resize (2 * m);
        rep (i, m, 2 * m - 1) {
            A[i] = A[i - m];
            B[i] = B[i - m];
        }
        rep (i, 0, n - 1) {
            rep (j, 0, 2 * m - 1) {
                int pos = lower_bound(ALL(B[j]), C[i]) - B[j].begin();
                if (pos == SZ(B[j]) || B[j][pos] != C[i]) dp[i][j] = 0;
                else dp[i][j] = 1;
            }
        }
        reb (i, n - 1, 0) {
            reb (j, 2 * m - 1, 0) {
                if (dp[i][j] != 0) dp[i][j] = dp[i + 1][j + 1] + 1;
                if (dp[i][j] >= m) ok[i + 1] = 1;
            }
        }
        rep (i, 1, n) f[i] = INF;
        ST.init(n);
        f[m] = ok[1] ? 1 : INF;
        ST.update (m, f[m]);
        rep (i, 2, n - m + 1) {
            if (ok[i]) {
                f[i + m - 1] = ST.get (i - 1, i + m - 1) + 1;
                ST.update (i + m - 1, f[i + m - 1]);
            }
        }
        if (f[n] < INF) return f[n];
        else return -1;
    }
}


int minimumInstructions (int _n, int _m, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B) {
//void solution() {
//    cin >> n >> m >> K;
    n = _n;
    m = _m;
    K = _K;
    C = _C;
    A = _A;
    B = _B;
//    C.resize(n);
//    rep (i, 0, n - 1) {
//        cin >> C[i];
//
//    }
//    A.resize (m);
//    B.resize (m);
//    rep (i, 0, m - 1) {
//        cin >> A[i];
//        B[i].resize (A[i]);
//        rep (j, 0, A[i] - 1) {
//            cin >> B[i][j];
//        }
//    }
//    if (n <= 20000 && m <= 2000)
    return sub4 :: solution();
//        cout << sub4 :: solution() <<"\n";
//    else sub5 :: solution();
}

//#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
//int main () {
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
////    file ("c");
//    int num_Test = 1;
////    cin >> num_Test;
//    while (num_Test--)
//        solution();
//}
/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4

5 4 4
1 0 1 2 2
2 0 1
1 1
1 2
1 3

*/

Compilation message

paint.cpp: In member function 'void sub4::Segment_Tree::update(int, int, int, int, int)':
paint.cpp:56:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |             int mid = l + r >> 1;
      |                       ~~^~~
paint.cpp: In member function 'int sub4::Segment_Tree::get(int, int, int, int, int)':
paint.cpp:64:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |             int mid = l + r >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2492 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 15 ms 12892 KB Output is correct
23 Correct 14 ms 12636 KB Output is correct
24 Correct 14 ms 12660 KB Output is correct
25 Correct 33 ms 92508 KB Output is correct
26 Correct 32 ms 94124 KB Output is correct
27 Correct 32 ms 92508 KB Output is correct
28 Correct 41 ms 93008 KB Output is correct
29 Correct 30 ms 94556 KB Output is correct
30 Correct 36 ms 93300 KB Output is correct
31 Correct 1043 ms 316756 KB Output is correct
32 Correct 977 ms 316756 KB Output is correct
33 Correct 981 ms 316976 KB Output is correct
34 Correct 948 ms 316752 KB Output is correct
35 Correct 982 ms 317048 KB Output is correct
36 Correct 959 ms 316920 KB Output is correct
37 Execution timed out 1551 ms 318292 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2492 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10584 KB Output is correct
11 Correct 2 ms 10584 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 6612 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 8668 KB Output is correct
31 Correct 1 ms 10588 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 10584 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 2 ms 8644 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 1 ms 8540 KB Output is correct
39 Correct 1 ms 8540 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 2 ms 8536 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 2 ms 10708 KB Output is correct
45 Correct 1 ms 10588 KB Output is correct
46 Correct 1 ms 10588 KB Output is correct
47 Correct 2 ms 10584 KB Output is correct
48 Correct 2 ms 10588 KB Output is correct
49 Correct 2 ms 10588 KB Output is correct
50 Correct 2 ms 10696 KB Output is correct
51 Correct 2 ms 10588 KB Output is correct
52 Correct 2 ms 10588 KB Output is correct
53 Correct 2 ms 10588 KB Output is correct
54 Correct 2 ms 10768 KB Output is correct
55 Correct 2 ms 10588 KB Output is correct
56 Correct 2 ms 10588 KB Output is correct
57 Correct 3 ms 10588 KB Output is correct
58 Correct 2 ms 10588 KB Output is correct
59 Correct 2 ms 10584 KB Output is correct
60 Correct 3 ms 10584 KB Output is correct
61 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 15 ms 12892 KB Output is correct
25 Correct 14 ms 12636 KB Output is correct
26 Correct 14 ms 12660 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 6612 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 8668 KB Output is correct
34 Correct 1 ms 10588 KB Output is correct
35 Correct 1 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 2 ms 10584 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 2 ms 8644 KB Output is correct
40 Correct 1 ms 8540 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 1 ms 8540 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 8536 KB Output is correct
45 Correct 2 ms 10588 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 2 ms 10708 KB Output is correct
48 Correct 1 ms 10588 KB Output is correct
49 Correct 1 ms 10588 KB Output is correct
50 Correct 2 ms 10584 KB Output is correct
51 Correct 2 ms 10588 KB Output is correct
52 Correct 2 ms 10588 KB Output is correct
53 Correct 2 ms 10696 KB Output is correct
54 Correct 2 ms 10588 KB Output is correct
55 Correct 2 ms 10588 KB Output is correct
56 Correct 2 ms 10588 KB Output is correct
57 Correct 2 ms 10768 KB Output is correct
58 Correct 2 ms 10588 KB Output is correct
59 Correct 2 ms 10588 KB Output is correct
60 Correct 3 ms 10588 KB Output is correct
61 Correct 2 ms 10588 KB Output is correct
62 Correct 2 ms 10584 KB Output is correct
63 Correct 3 ms 10584 KB Output is correct
64 Correct 2 ms 10588 KB Output is correct
65 Correct 1 ms 6492 KB Output is correct
66 Correct 1 ms 10588 KB Output is correct
67 Correct 2 ms 10588 KB Output is correct
68 Correct 2 ms 10584 KB Output is correct
69 Correct 2 ms 10584 KB Output is correct
70 Correct 4 ms 10840 KB Output is correct
71 Correct 4 ms 10808 KB Output is correct
72 Correct 3 ms 8904 KB Output is correct
73 Correct 2 ms 8796 KB Output is correct
74 Correct 3 ms 8796 KB Output is correct
75 Correct 3 ms 8796 KB Output is correct
76 Correct 11 ms 10844 KB Output is correct
77 Correct 9 ms 11100 KB Output is correct
78 Correct 12 ms 11612 KB Output is correct
79 Correct 2 ms 10588 KB Output is correct
80 Correct 3 ms 10588 KB Output is correct
81 Correct 2 ms 10584 KB Output is correct
82 Correct 2 ms 10588 KB Output is correct
83 Correct 2 ms 10588 KB Output is correct
84 Correct 5 ms 11044 KB Output is correct
85 Correct 6 ms 10844 KB Output is correct
86 Correct 6 ms 10840 KB Output is correct
87 Correct 5 ms 10844 KB Output is correct
88 Correct 5 ms 11044 KB Output is correct
89 Correct 5 ms 10844 KB Output is correct
90 Correct 18 ms 14084 KB Output is correct
91 Correct 19 ms 13908 KB Output is correct
92 Correct 18 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 15 ms 12892 KB Output is correct
25 Correct 14 ms 12636 KB Output is correct
26 Correct 14 ms 12660 KB Output is correct
27 Correct 33 ms 92508 KB Output is correct
28 Correct 32 ms 94124 KB Output is correct
29 Correct 32 ms 92508 KB Output is correct
30 Correct 41 ms 93008 KB Output is correct
31 Correct 30 ms 94556 KB Output is correct
32 Correct 36 ms 93300 KB Output is correct
33 Correct 1043 ms 316756 KB Output is correct
34 Correct 977 ms 316756 KB Output is correct
35 Correct 981 ms 316976 KB Output is correct
36 Correct 948 ms 316752 KB Output is correct
37 Correct 982 ms 317048 KB Output is correct
38 Correct 959 ms 316920 KB Output is correct
39 Execution timed out 1551 ms 318292 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2492 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 10588 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10584 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 1 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 15 ms 12892 KB Output is correct
25 Correct 14 ms 12636 KB Output is correct
26 Correct 14 ms 12660 KB Output is correct
27 Correct 33 ms 92508 KB Output is correct
28 Correct 32 ms 94124 KB Output is correct
29 Correct 32 ms 92508 KB Output is correct
30 Correct 41 ms 93008 KB Output is correct
31 Correct 30 ms 94556 KB Output is correct
32 Correct 36 ms 93300 KB Output is correct
33 Correct 1043 ms 316756 KB Output is correct
34 Correct 977 ms 316756 KB Output is correct
35 Correct 981 ms 316976 KB Output is correct
36 Correct 948 ms 316752 KB Output is correct
37 Correct 982 ms 317048 KB Output is correct
38 Correct 959 ms 316920 KB Output is correct
39 Execution timed out 1551 ms 318292 KB Time limit exceeded
40 Halted 0 ms 0 KB -