Submission #1067855

# Submission time Handle Problem Language Result Execution time Memory
1067855 2024-08-21T04:42:25 Z thinknoexit Wombats (IOI13_wombats) C++17
39 / 100
20000 ms 48168 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][M]; // cost from (i, j) -> (i+1, j)
int cc[N][M]; // cost from (i, j) -> (i, j+1)
int dp[111][111];
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];
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];
    memset(dp, 0x3f, sizeof dp);
    dp[0][V1] = 0;
    for (int i = V1 - 1;i >= 0;i--) {
        dp[0][i] = dp[0][i + 1] + cc[0][i];
    }
    for (int i = V1 + 1;i < m;i++) {
        dp[0][i] = dp[0][i - 1] + cc[0][i - 1];
    }
    for (int i = 1;i < n;i++) {
        for (int j = 0;j < m;j++) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + rc[i - 1][j]);
            int sum = 0;
            for (int k = j + 1;k < m;k++) {
                sum += cc[i][k - 1];
                dp[i][k] = min(dp[i][k],
                    dp[i - 1][j] + rc[i - 1][j] + sum);
            }
            sum = 0;
            for (int k = j - 1;j >= 0;j--) {
                sum += cc[i][k];
                dp[i][k] = min(dp[i][k],
                    dp[i - 1][j] + rc[i - 1][j] + sum);
            }
        }
    }
    return dp[n - 1][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;
      |      ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:113:31: warning: array subscript -1 is below array bounds of 'int [22]' [-Warray-bounds]
  113 |                 sum += cc[i][k];
      |                        ~~~~~~~^
wombats.cpp:114:39: warning: array subscript -1 is below array bounds of 'int [111]' [-Warray-bounds]
  114 |                 dp[i][k] = min(dp[i][k],
      |                                ~~~~~~~^
wombats.cpp:114:24: warning: array subscript -1 is below array bounds of 'int [111]' [-Warray-bounds]
  114 |                 dp[i][k] = min(dp[i][k],
      |                 ~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 44892 KB Output is correct
2 Correct 7 ms 44816 KB Output is correct
3 Correct 42 ms 46592 KB Output is correct
4 Correct 7 ms 44892 KB Output is correct
5 Correct 7 ms 45000 KB Output is correct
6 Correct 4 ms 40284 KB Output is correct
7 Correct 4 ms 40280 KB Output is correct
8 Correct 4 ms 40284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 40280 KB Output is correct
2 Correct 4 ms 40284 KB Output is correct
3 Correct 5 ms 40284 KB Output is correct
4 Correct 5 ms 42332 KB Output is correct
5 Correct 5 ms 42332 KB Output is correct
6 Correct 5 ms 42332 KB Output is correct
7 Correct 5 ms 42332 KB Output is correct
8 Correct 5 ms 42228 KB Output is correct
9 Correct 5 ms 42332 KB Output is correct
10 Correct 6 ms 42224 KB Output is correct
11 Correct 48 ms 43196 KB Output is correct
12 Correct 5 ms 42328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 20050 ms 42332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 47448 KB Output is correct
2 Correct 9 ms 47452 KB Output is correct
3 Correct 9 ms 47504 KB Output is correct
4 Correct 27 ms 48168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 20068 ms 42332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 20059 ms 42332 KB Time limit exceeded
2 Halted 0 ms 0 KB -