Submission #765834

# Submission time Handle Problem Language Result Execution time Memory
765834 2023-06-25T06:14:28 Z fefe Wombats (IOI13_wombats) C++17
12 / 100
157 ms 16468 KB
#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;

const int inf = 0x3fffffff;

// duplication of the original data
int r, c;
int dr;
int h[5200][200], v[5200][200];

// related with sqrt-decomposition
int block[73][200][200];
int res[200][200];
int bn;

// array used in merge function
int D[200][200];
int temp[200][200];
void merge(int A[200][200], int B[200][200], int cost[200], int M[200][200]) {
    // s == e
    for (int i = 0; i < c; i++) {
        temp[i][i] = inf;
        D[i][i] = i;
        for (int j = 0; j < c; j++) {
            if (temp[i][i] > A[i][j] + cost[j] + B[j][i]) {
                temp[i][i] = A[i][j] + cost[j] + B[j][i];
                D[i][i] = j;
            }
        }
    }

    // s < e

    for (int len = 2; len <= c; len++) {
        for (int s = 0; s <= c - len; s++) {
            int e = s + len - 1;
            temp[s][e] = inf;
            D[s][e] = s;
            for (int i = D[s][e - 1]; i <= D[s + 1][e]; i++) {
                if (temp[s][e] > A[s][i] + cost[i] + B[i][e]) {
                    temp[s][e] = A[s][i] + cost[i] + B[i][e];
                    D[s][e] = i;
                }
            }

        }
    }

    // s > e

    for (int len = 2; len <= c; len++) {
        for (int s = len - 1; s < c; s++) {
            int e = s - len + 1;
            temp[s][e] = inf;
            D[s][e] = s;
            for (int i = D[s - 1][e]; i <= D[s][e + 1]; i++) {
                if (temp[s][e] > A[s][i] + cost[i] + B[i][e]) {
                    temp[s][e] = A[s][i] + cost[i] + B[i][e];
                    D[s][e] = i;
                }
            }
        }
    }

    for (int s = 0; s < c; s++) {
        for (int e = 0; e < c; e++) {
            M[s][e] = temp[s][e];
        }
    }
}

void set_mono(int i, int A[200][200]) {
    for (int s = 0; s < c; s++) {
        A[s][s] = 0;
        for (int e = s + 1; e < c; e++) {
            A[s][e] = A[s][e - 1] + h[i][e - 1];
            A[e][s] = A[s][e];
        }
    }
}

// array used in set_block function
int tmp[200][200];
void set_block(int idx) {
    int ed = min(r, idx * dr + dr);
    set_mono(idx * dr, block[idx]);
    for (int i = idx * dr + 1; i < ed; i++) {
        set_mono(i, tmp);
        merge(block[idx], tmp, v[i - 1], block[idx]);
    }
}

void copy_A_to_B(int A[200][200], int B[200][200]) {
    for (int i = 0; i < 200; i++) {
        for (int j = 0; j < 200; j++) {
            B[i][j] = A[i][j];
        }
    }
}
void get_res() {
    copy_A_to_B(block[0], res);
    for (int idx = 1; idx < bn; idx++) {
        merge(res, block[idx], v[idx * dr - 1], res);
    }

}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    r = R;
    c = C;
    dr = sqrt(r);
    bn = r % dr ? r / dr + 1 : r / dr;

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            h[i][j] = H[i][j];
            v[i][j] = V[i][j];
        }
    }
    
    for (int idx = 0; idx < bn; idx++) {
        set_block(idx);
    }
    get_res();
}

void changeH(int P, int Q, int W) {
    h[P][Q] = W;
    set_block(P / dr);
    get_res();
}


void changeV(int P, int Q, int W) {
    v[P][Q] = W;
    if ((P - 1) % dr != 0) {
        set_block(P / dr);
    }
    get_res();
}

int escape(int V1, int V2) {
    return res[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 12500 KB Output is correct
2 Incorrect 8 ms 12428 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 52 ms 1636 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 1940 KB Output is correct
2 Correct 102 ms 1936 KB Output is correct
3 Correct 153 ms 1860 KB Output is correct
4 Correct 141 ms 1748 KB Output is correct
5 Incorrect 157 ms 1748 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 16468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 147 ms 1940 KB Output is correct
2 Correct 96 ms 1920 KB Output is correct
3 Correct 150 ms 1852 KB Output is correct
4 Correct 140 ms 1748 KB Output is correct
5 Incorrect 141 ms 1840 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 144 ms 1924 KB Output is correct
2 Correct 95 ms 1924 KB Output is correct
3 Correct 153 ms 1852 KB Output is correct
4 Correct 141 ms 1824 KB Output is correct
5 Incorrect 141 ms 1844 KB Output isn't correct
6 Halted 0 ms 0 KB -