Submission #321299

# Submission time Handle Problem Language Result Execution time Memory
321299 2020-11-12T01:46:23 Z thecodingwizard Wombats (IOI13_wombats) C++11
100 / 100
13265 ms 192248 KB
#include <bits/stdc++.h>
#include "wombats.h"

using namespace std;

using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010

int n, c;
int BLOCK = 10;
int H[5000][200], V[5000][200];
int psH[5001][200];

int st[(1 << 11)][200][200];

// Merges A with B, storing the result in C
void merge(int A[200][200], int B[200][200], int C[200][200]) {
    int p[200][200];
    F0R(i, c) F0R(j, c) C[i][j] = inf;
    for (int len = -c; len <= c; len++) {
        F0R(i, c) {
            int j = i + len;
            if (j >= 0 && j < c) {
                int lowerBound = j-1>=0?p[i][j-1]:0, upperBound = i+1<c?p[i+1][j]:c-1;
                for (int tgt = lowerBound; tgt <= upperBound; tgt++) {
                    if (C[i][j] >= A[i][tgt] + B[tgt][j]) {
                        C[i][j] = A[i][tgt] + B[tgt][j];
                        p[i][j] = tgt;
                    }
                }
            }
        }
    }
}

void build(int p, int i, int j) {
    if (j - i + 1 <= BLOCK) {
        FOR(rowIdx, i, j+1) {
            int x[200][200], y[200][200], z[200][200];
            F0R(idx, c) {
                F0R(idx2, c) {
                    x[idx][idx2] = abs(psH[rowIdx][idx2]-psH[rowIdx][idx])+V[rowIdx][idx2];
                    y[idx][idx2] = abs(psH[rowIdx+1][idx2]-psH[rowIdx+1][idx]);
                }
            }
            merge(x, y, z);
            int tmp[200][200];
            if (rowIdx == i) {
                F0R(a, c) F0R(b, c) tmp[a][b] = z[a][b];
            } else {
                merge(st[p], z, tmp);
            }
            F0R(a, c) F0R(b, c) st[p][a][b] = tmp[a][b];
        }
        return;
    }
    build(p*2, i, (i+j)/2);
    build(p*2+1, (i+j)/2+1, j);
    merge(st[p*2], st[p*2+1], st[p]);
}

void upd(int p, int i, int j, int k) {
    if (k > j+1 || k < i) return;
    if (j - i + 1 <= BLOCK && i <= k && k <= j+1) {
        build(p, i, j);
        return;
    }
    upd(p*2, i, (i+j)/2, k);
    upd(p*2+1, (i+j)/2+1, j, k);
    merge(st[p*2], st[p*2+1], st[p]);
}

void init(int R, int C, int _H[5000][200], int _V[5000][200]) {
    n = R; c = C; F0R(i, R) F0R(j, C) { H[i][j] = _H[i][j]; V[i][j] = _V[i][j]; }
    F0R(i, n) F0R(j, c) psH[i][j] = j == 0 ? 0 : psH[i][j-1] + H[i][j-1];
    build(1, 0, n-2);

    //F0R(i, c) F0R(j, c) { cerr << "(" << i << ", " << j << "): " << st[1][i][j] << endl; }
}

void changeH(int P, int Q, int W) {
    H[P][Q] = W;
    F0R(j, c) psH[P][j] = j == 0 ? 0 : psH[P][j-1] + H[P][j-1];
    upd(1, 0, n-2, P);
}

void changeV(int P, int Q, int W) {
    V[P][Q] = W;
    upd(1, 0, n-2, P);
}

int escape(int V1, int V2) {
    return st[1][V1][V2];
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 20460 KB Output is correct
2 Correct 12 ms 20460 KB Output is correct
3 Correct 90 ms 23268 KB Output is correct
4 Correct 12 ms 20480 KB Output is correct
5 Correct 12 ms 20460 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 78 ms 1636 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 275 ms 4068 KB Output is correct
2 Correct 218 ms 3684 KB Output is correct
3 Correct 276 ms 3940 KB Output is correct
4 Correct 279 ms 3940 KB Output is correct
5 Correct 278 ms 3812 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1020 ms 3936 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 25196 KB Output is correct
2 Correct 16 ms 25196 KB Output is correct
3 Correct 18 ms 25196 KB Output is correct
4 Correct 57 ms 26600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 3688 KB Output is correct
2 Correct 221 ms 3684 KB Output is correct
3 Correct 276 ms 3940 KB Output is correct
4 Correct 278 ms 3820 KB Output is correct
5 Correct 279 ms 3820 KB Output is correct
6 Correct 16 ms 25196 KB Output is correct
7 Correct 16 ms 25196 KB Output is correct
8 Correct 16 ms 25196 KB Output is correct
9 Correct 56 ms 26596 KB Output is correct
10 Correct 12 ms 20460 KB Output is correct
11 Correct 12 ms 20460 KB Output is correct
12 Correct 92 ms 23396 KB Output is correct
13 Correct 12 ms 20460 KB Output is correct
14 Correct 12 ms 20460 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 620 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 81 ms 2920 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1014 ms 3940 KB Output is correct
28 Correct 2985 ms 108508 KB Output is correct
29 Correct 3144 ms 104652 KB Output is correct
30 Correct 3151 ms 104576 KB Output is correct
31 Correct 3058 ms 110220 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 278 ms 3812 KB Output is correct
2 Correct 219 ms 3812 KB Output is correct
3 Correct 278 ms 3940 KB Output is correct
4 Correct 283 ms 3940 KB Output is correct
5 Correct 281 ms 3812 KB Output is correct
6 Correct 16 ms 25196 KB Output is correct
7 Correct 16 ms 25196 KB Output is correct
8 Correct 16 ms 25196 KB Output is correct
9 Correct 58 ms 26596 KB Output is correct
10 Correct 12 ms 20480 KB Output is correct
11 Correct 12 ms 20460 KB Output is correct
12 Correct 90 ms 23268 KB Output is correct
13 Correct 13 ms 20460 KB Output is correct
14 Correct 12 ms 20460 KB Output is correct
15 Correct 4886 ms 191072 KB Output is correct
16 Correct 13265 ms 192248 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 620 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 81 ms 2916 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1025 ms 3936 KB Output is correct
30 Correct 2979 ms 108772 KB Output is correct
31 Correct 11303 ms 189656 KB Output is correct
32 Correct 11404 ms 189428 KB Output is correct
33 Correct 3143 ms 104812 KB Output is correct
34 Correct 11324 ms 185852 KB Output is correct
35 Correct 3130 ms 104840 KB Output is correct
36 Correct 11441 ms 185224 KB Output is correct
37 Correct 3059 ms 110100 KB Output is correct
38 Correct 11631 ms 189916 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11586 ms 185348 KB Output is correct