Submission #1067865

# Submission time Handle Problem Language Result Execution time Memory
1067865 2024-08-21T04:50:18 Z thinknoexit Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 102224 KB
#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5050;
const int M = 22;
int rc[N][101]; // cost from (i, j) -> (i+1, j)
int cc[N][101]; // cost from (i, j) -> (i, j+1)
int n, m;
struct A {
    int dis[M][M], r;
    A() { memset(dis, 0x3f, sizeof dis), r = 0; }
    A operator + (const A& o) const {
        A res;
        for (int i = 0;i < m;i++) {
            for (int j = 0;j < m;j++) {
                for (int k = 0;k < m;k++) {
                    res.dis[i][j] = min(res.dis[i][j],
                        dis[i][k] + rc[r][k] + o.dis[k][j]);
                }
            }
        }
        res.r = o.r;
        return res;
    }
} tree[4 * N];
struct B {
    int dis[101][101], r;
    B() { memset(dis, 0x3f, sizeof dis), r = 0; }
    B operator + (const B& o) const {
        B res;
        for (int i = 0;i < m;i++) {
            for (int j = 0;j < m;j++) {
                for (int k = 0;k < m;k++) {
                    res.dis[i][j] = min(res.dis[i][j],
                        dis[i][k] + rc[r][k] + o.dis[k][j]);
                }
            }
        }
        res.r = o.r;
        return res;
    }
};
void build(int now = 1, int l = 0, int r = n - 1) {
    if (l == r) {
        vector<int> sum(m);
        sum[0] = 0;
        for (int i = 1;i < m;i++) {
            sum[i] = sum[i - 1] + cc[l][i - 1];
        }
        for (int i = 0;i < m;i++) {
            for (int j = i;j < m;j++) {
                tree[now].dis[i][j] = tree[now].dis[j][i] = sum[j] - sum[i];
            }
        }
        tree[now].r = r;
        return;
    }
    int mid = (l + r) / 2;
    build(2 * now, l, mid), build(2 * now + 1, mid + 1, r);
    tree[now] = tree[2 * now] + tree[2 * now + 1];
};
void update(int v, int now = 1, int l = 0, int r = n - 1) {
    if (l == r) {
        vector<int> sum(m);
        sum[0] = 0;
        for (int i = 1;i < m;i++) {
            sum[i] = sum[i - 1] + cc[l][i - 1];
        }
        for (int i = 0;i < m;i++) {
            for (int j = i;j < m;j++) {
                tree[now].dis[i][j] = tree[now].dis[j][i] = sum[j] - sum[i];
            }
        }
        tree[now].r = r;
        return;
    }
    int mid = (l + r) / 2;
    if (v <= mid) update(v, 2 * now, l, mid);
    else update(v, 2 * now + 1, mid + 1, r);
    tree[now] = tree[2 * now] + tree[2 * now + 1];
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n = R, m = C;
    for (int i = 0;i < n - 1;i++) {
        for (int j = 0;j < m;j++) {
            rc[i][j] = V[i][j];
        }
    }
    for (int i = 0;i < n;i++) {
        for (int j = 0;j < m - 1;j++) {
            cc[i][j] = H[i][j];
        }
    }
    if (m <= 20) build();
}

void changeH(int P, int Q, int W) {
    cc[P][Q] = W;
    if (m <= 20) update(P);
}

void changeV(int P, int Q, int W) {
    rc[P][Q] = W;
    if (m <= 20) update(P);
}

int escape(int V1, int V2) {
    if (m <= 20) return tree[1].dis[V1][V2];
    auto cal = [&](int r) {
        B now;
        vector<int> sum(m);
        sum[0] = 0;
        for (int i = 1;i < m;i++) {
            sum[i] = sum[i - 1] + cc[r][i - 1];
        }
        for (int i = 0;i < m;i++) {
            for (int j = i;j < m;j++) {
                now.dis[i][j] = now.dis[j][i] = sum[j] - sum[i];
            }
        }
        now.r = r;
        return now;};
    B now = cal(0);
    for (int i = 1;i < n;i++) {
        now = now + cal(i);
    }
    return now.dis[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 8 ms 48472 KB Output is correct
2 Correct 7 ms 48476 KB Output is correct
3 Correct 86 ms 49996 KB Output is correct
4 Correct 8 ms 48472 KB Output is correct
5 Correct 10 ms 48476 KB Output is correct
6 Correct 6 ms 43504 KB Output is correct
7 Correct 5 ms 43612 KB Output is correct
8 Correct 5 ms 43612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 43488 KB Output is correct
2 Correct 5 ms 43484 KB Output is correct
3 Correct 5 ms 43484 KB Output is correct
4 Correct 5 ms 45660 KB Output is correct
5 Correct 6 ms 45660 KB Output is correct
6 Correct 5 ms 45660 KB Output is correct
7 Correct 5 ms 45660 KB Output is correct
8 Correct 5 ms 45660 KB Output is correct
9 Correct 5 ms 45544 KB Output is correct
10 Correct 5 ms 45536 KB Output is correct
11 Correct 78 ms 46676 KB Output is correct
12 Correct 5 ms 45660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7455 ms 45752 KB Output is correct
2 Correct 7462 ms 45656 KB Output is correct
3 Correct 7872 ms 45752 KB Output is correct
4 Correct 7582 ms 45748 KB Output is correct
5 Correct 7360 ms 45752 KB Output is correct
6 Correct 6 ms 43608 KB Output is correct
7 Correct 6 ms 43612 KB Output is correct
8 Correct 5 ms 43612 KB Output is correct
9 Correct 7670 ms 45756 KB Output is correct
10 Correct 5 ms 45660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 50520 KB Output is correct
2 Correct 9 ms 50524 KB Output is correct
3 Correct 10 ms 50524 KB Output is correct
4 Correct 45 ms 51368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7802 ms 45756 KB Output is correct
2 Correct 7607 ms 45748 KB Output is correct
3 Correct 7970 ms 45756 KB Output is correct
4 Correct 7590 ms 45748 KB Output is correct
5 Correct 7617 ms 45660 KB Output is correct
6 Correct 11 ms 50524 KB Output is correct
7 Correct 9 ms 50656 KB Output is correct
8 Correct 9 ms 50660 KB Output is correct
9 Correct 47 ms 51300 KB Output is correct
10 Correct 7 ms 48476 KB Output is correct
11 Correct 7 ms 48648 KB Output is correct
12 Correct 89 ms 50228 KB Output is correct
13 Correct 8 ms 48476 KB Output is correct
14 Correct 9 ms 48476 KB Output is correct
15 Correct 5 ms 43612 KB Output is correct
16 Correct 5 ms 43608 KB Output is correct
17 Correct 5 ms 43612 KB Output is correct
18 Correct 6 ms 45656 KB Output is correct
19 Correct 6 ms 45656 KB Output is correct
20 Correct 5 ms 45660 KB Output is correct
21 Correct 6 ms 45532 KB Output is correct
22 Correct 5 ms 45660 KB Output is correct
23 Correct 6 ms 45660 KB Output is correct
24 Correct 5 ms 45656 KB Output is correct
25 Correct 80 ms 46672 KB Output is correct
26 Correct 6 ms 45660 KB Output is correct
27 Correct 7800 ms 45756 KB Output is correct
28 Execution timed out 20026 ms 50516 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7770 ms 45756 KB Output is correct
2 Correct 7520 ms 45660 KB Output is correct
3 Correct 7902 ms 45660 KB Output is correct
4 Correct 8122 ms 45752 KB Output is correct
5 Correct 7629 ms 45756 KB Output is correct
6 Correct 9 ms 50524 KB Output is correct
7 Correct 9 ms 50700 KB Output is correct
8 Correct 9 ms 50520 KB Output is correct
9 Correct 48 ms 51464 KB Output is correct
10 Correct 8 ms 48476 KB Output is correct
11 Correct 8 ms 48548 KB Output is correct
12 Correct 81 ms 50164 KB Output is correct
13 Correct 7 ms 48476 KB Output is correct
14 Correct 9 ms 48476 KB Output is correct
15 Runtime error 161 ms 102224 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -