Submission #586844

# Submission time Handle Problem Language Result Execution time Memory
586844 2022-06-30T18:06:57 Z FatihSolak Wombats (IOI13_wombats) C++17
76 / 100
2438 ms 262144 KB
#include "wombats.h"
#include <bits/stdc++.h>
#define R 5005
#define C 205
using namespace std;
const int block = 15;
int r,c;
int h[R][C];
int w[R][C];
int opt[C][C];
struct node{
    int a[C][C];
    int l,r;
    node(int init){
        for(int i = 0;i<C;i++){
            for(int j = 0;j<C;j++){
                a[i][j] = init;
            }
        }
    }
};
node merge(node a,node b){
    node ret(1e9);
    for(int dif = -c-1;dif < c ;dif++){
        for(int i = max(0,-dif);i + dif<c;i++){
            int j = dif + i;
            int l = 0,r = c-1;
            if(j)
                l = opt[i][j-1];
            if(i + 1 != c)
                r = opt[i+1][j];
            for(int x = l;x<=r;x++){
                if(a.a[i][x] + b.a[x][j] < ret.a[i][j]){
                    ret.a[i][j] = a.a[i][x] + b.a[x][j];
                    opt[i][j] = x;
                }
            }
        }
    }
    return ret;
}
struct SegTree{
    vector<node> t;
    int n;
    void init(int size){
        n = size;
        t.assign(4*n,1e9);
        build(1,0,n-1);
    }
    void build(int v,int tl,int tr){
        t[v].l = tl * block;
        t[v].r = min(r-1,(tr + 1) * block - 1);
        if(tl == tr){
            for(int i = 0;i<c;i++){
                t[v].a[i][i] = 0;
                for(int j = t[v].l;j<=t[v].r;j++){
                    for(int d=1;d<c;d++){
                        t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d-1] + h[j][d-1]);
                    }
                    for(int d=c-2;d>=0;d--){
                        t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d+1] + h[j][d]);
                    }
                    for(int d=0;d<c;d++){
                        t[v].a[i][d] = t[v].a[i][d] + w[j][d];
                    }
                }
            }
            return;
        }
        int tm = (tl + tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
        t[v] = merge(t[v*2],t[v*2+1]);
    }
    void upd(int v,int tl,int tr,int pos){
        t[v].l = tl * block;
        t[v].r = min(r-1,(tr + 1) * block - 1);
        if(tl == tr){
            for(int i = 0;i<c;i++){
                t[v].a[i][i] = 0;
                for(int j = t[v].l;j<=t[v].r;j++){
                    for(int d=1;d<c;d++){
                        t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d-1] + h[j][d-1]);
                    }
                    for(int d=c-2;d>=0;d--){
                        t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d+1] + h[j][d]);
                    }
                    for(int d=0;d<c;d++){
                        t[v].a[i][d] = t[v].a[i][d] + w[j][d];
                    }
                }
            }
            return;
        }
        int tm = (tl + tr)/2;
        if(pos <= tm)
            upd(v*2,tl,tm,pos);
        else upd(v*2+1,tm+1,tr,pos);
        t[v] = merge(t[v*2],t[v*2+1]);
    }

    void upd(int pos){
        upd(1,0,n-1,pos);
    }

}tree;

void init(int r_, int c_, int h_[5000][200], int v_[5000][200]) {
    r = r_;
    c = c_;
    for(int i = 0;i<r;i++){
        for(int j = 0;j<c;j++){
            h[i][j] = h_[i][j];
            w[i][j] = v_[i][j];
        }
    }
    tree.init((r+block-1) / block);
}

void changeH(int p, int q, int x) {
    h[p][q] = x;
    tree.upd(p/block);
}

void changeV(int p, int q, int x) {
    w[p][q] = x;
    if(p % block == 0 && p)
        tree.upd(p/block - 1);
    tree.upd(p/block);
}

int escape(int v1, int v2) {
    return tree.t[1].a[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 321 ms 233744 KB Output is correct
2 Correct 311 ms 233764 KB Output is correct
3 Correct 358 ms 235352 KB Output is correct
4 Correct 375 ms 233756 KB Output is correct
5 Correct 307 ms 233812 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 2132 KB Output is correct
5 Correct 1 ms 2132 KB Output is correct
6 Correct 1 ms 2132 KB Output is correct
7 Correct 1 ms 2132 KB Output is correct
8 Correct 1 ms 2132 KB Output is correct
9 Correct 1 ms 2132 KB Output is correct
10 Correct 2 ms 2132 KB Output is correct
11 Correct 73 ms 3132 KB Output is correct
12 Correct 2 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 6148 KB Output is correct
2 Correct 182 ms 6044 KB Output is correct
3 Correct 195 ms 6148 KB Output is correct
4 Correct 184 ms 6100 KB Output is correct
5 Correct 188 ms 6100 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 833 ms 6156 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 316 ms 237716 KB Output is correct
2 Correct 308 ms 237644 KB Output is correct
3 Correct 357 ms 237724 KB Output is correct
4 Correct 351 ms 238492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 6080 KB Output is correct
2 Correct 184 ms 6100 KB Output is correct
3 Correct 187 ms 6100 KB Output is correct
4 Correct 206 ms 6100 KB Output is correct
5 Correct 175 ms 6164 KB Output is correct
6 Correct 303 ms 237716 KB Output is correct
7 Correct 299 ms 237720 KB Output is correct
8 Correct 313 ms 237724 KB Output is correct
9 Correct 360 ms 238520 KB Output is correct
10 Correct 311 ms 233804 KB Output is correct
11 Correct 344 ms 233812 KB Output is correct
12 Correct 494 ms 235352 KB Output is correct
13 Correct 359 ms 233804 KB Output is correct
14 Correct 341 ms 233816 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 2132 KB Output is correct
19 Correct 2 ms 2132 KB Output is correct
20 Correct 1 ms 2132 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 1 ms 2132 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 2 ms 2132 KB Output is correct
25 Correct 75 ms 3136 KB Output is correct
26 Correct 3 ms 2132 KB Output is correct
27 Correct 854 ms 6172 KB Output is correct
28 Correct 2011 ms 238248 KB Output is correct
29 Correct 1918 ms 198588 KB Output is correct
30 Correct 1951 ms 199392 KB Output is correct
31 Correct 2438 ms 243632 KB Output is correct
32 Correct 1 ms 1088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 6100 KB Output is correct
2 Correct 184 ms 6168 KB Output is correct
3 Correct 189 ms 6168 KB Output is correct
4 Correct 274 ms 6152 KB Output is correct
5 Correct 189 ms 6100 KB Output is correct
6 Correct 346 ms 237720 KB Output is correct
7 Correct 348 ms 237724 KB Output is correct
8 Correct 342 ms 237724 KB Output is correct
9 Correct 430 ms 238468 KB Output is correct
10 Correct 341 ms 233708 KB Output is correct
11 Correct 305 ms 233804 KB Output is correct
12 Correct 392 ms 235352 KB Output is correct
13 Correct 336 ms 233716 KB Output is correct
14 Correct 320 ms 233752 KB Output is correct
15 Runtime error 732 ms 262144 KB Execution killed with signal 6
16 Halted 0 ms 0 KB -