Submission #1030165

# Submission time Handle Problem Language Result Execution time Memory
1030165 2024-07-21T22:07:21 Z noyancanturk Wombats (IOI13_wombats) C++17
100 / 100
18418 ms 46904 KB
#include "wombats.h"

#include <bits/stdc++.h>
using namespace std;

int n,c;
int h[5000][200],v[5000][200];
using mat=int[200][200];

mat dp;
 
void calc(int l,int r){
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            dp[i][j]=2e9;
        }
        dp[i][i]=0;
    }
    if(1<c){
        for(int i=1;i<c;i++){
            for(int j=0;j<i;j++){
                dp[i][j]=min(dp[i][j],dp[i-1][j]+h[r][i-1]);
            }
        }
        for(int i=c-2;0<=i;i--){
            for(int j=c-1;i<j;j--){
                dp[i][j]=min(dp[i][j],dp[i+1][j]+h[r][i]);
            }
        }
    }
    for(int i=r-1;l<=i;i--){
        for(int j=0;j<c;j++){
            for(int k=0;k<c;k++){
                dp[j][k]+=v[i][j];
            }
        }
        if(1<c){
            for(int j=1;j<c;j++){
                for(int k=0;k<c;k++){
                    dp[j][k]=min(dp[j][k],dp[j-1][k]+h[i][j-1]);
                }
            }
            for(int j=c-2;0<=j;j--){
                for(int k=0;k<c;k++){
                    dp[j][k]=min(dp[j][k],dp[j+1][k]+h[i][j]);
                }
            }
        }
    }
}

struct{
    mat tree[800];
    #define cur tree[node]
    void build(int l,int r,int node){
        if(r-l<100){    
            calc(l,r+1);
            for(int i=0;i<c;i++){
                for(int j=0;j<c;j++){
                    cur[i][j]=dp[i][j];
                }
            }
            return;
        }
        int mid=(l+r)>>1,child=node<<1;
        build(l,mid,child),build(mid+1,r,child|1);
        for(int i=0;i<c;i++){
            for(int j=0;j<c;j++){
                cur[i][j]=INT_MAX;
                for(int k=0;k<c;k++){
                    cur[i][j]=min(cur[i][j],tree[child][i][k]+tree[child|1][k][j]);
                }
            }
        }
    }
    int P;
    void update(int l,int r,int node){
        if(r-l<100){    
            calc(l,r+1);
            for(int i=0;i<c;i++){
                for(int j=0;j<c;j++){
                    cur[i][j]=dp[i][j];
                }
            }
            return;
        }
        int mid=(l+r)>>1,child=node<<1;
        if(P<=mid)update(l,mid,child);
        else update(mid+1,r,child|1);
        for(int i=0;i<c;i++){
            for(int j=0;j<c;j++){
                cur[i][j]=INT_MAX;
                for(int k=0;k<c;k++){
                    cur[i][j]=min(cur[i][j],tree[child][i][k]+tree[child|1][k][j]);
                }
            }
        }
    }
    void update(int p){
        P=p;
        update(0,n-2,1);
    }
}st;

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n=R;
    c=C;
    for(int i=0;i<n;i++){
        for(int j=0;j<c;j++){
            h[i][j]=H[i][j];
            v[i][j]=V[i][j];
        }
    }
    st.build(0,n-2,1);
}

void changeH(int P, int Q, int W) {
    h[P][Q]=W;
    st.update(P);
}

void changeV(int P, int Q, int W) {
    v[P][Q]=W;
    st.update(P);
}

int escape(int V1, int V2) {
    return st.tree[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 5 ms 12636 KB Output is correct
2 Correct 5 ms 12636 KB Output is correct
3 Correct 43 ms 15312 KB Output is correct
4 Correct 5 ms 12632 KB Output is correct
5 Correct 5 ms 12636 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 40 ms 2816 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 1004 KB Output is correct
2 Correct 158 ms 860 KB Output is correct
3 Correct 162 ms 860 KB Output is correct
4 Correct 172 ms 856 KB Output is correct
5 Correct 158 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 802 ms 860 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16984 KB Output is correct
2 Correct 7 ms 16764 KB Output is correct
3 Correct 7 ms 16732 KB Output is correct
4 Correct 28 ms 18020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 188 ms 828 KB Output is correct
2 Correct 183 ms 860 KB Output is correct
3 Correct 195 ms 1108 KB Output is correct
4 Correct 181 ms 1008 KB Output is correct
5 Correct 197 ms 1004 KB Output is correct
6 Correct 8 ms 16728 KB Output is correct
7 Correct 7 ms 16732 KB Output is correct
8 Correct 10 ms 16732 KB Output is correct
9 Correct 27 ms 18012 KB Output is correct
10 Correct 6 ms 12632 KB Output is correct
11 Correct 5 ms 12708 KB Output is correct
12 Correct 43 ms 15448 KB Output is correct
13 Correct 5 ms 12632 KB Output is correct
14 Correct 5 ms 12636 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 39 ms 2720 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 880 ms 860 KB Output is correct
28 Correct 2935 ms 30564 KB Output is correct
29 Correct 2707 ms 27476 KB Output is correct
30 Correct 2675 ms 27476 KB Output is correct
31 Correct 2987 ms 32396 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 188 ms 1016 KB Output is correct
2 Correct 177 ms 856 KB Output is correct
3 Correct 183 ms 860 KB Output is correct
4 Correct 181 ms 856 KB Output is correct
5 Correct 177 ms 996 KB Output is correct
6 Correct 8 ms 16732 KB Output is correct
7 Correct 8 ms 16732 KB Output is correct
8 Correct 9 ms 16732 KB Output is correct
9 Correct 34 ms 18120 KB Output is correct
10 Correct 5 ms 12632 KB Output is correct
11 Correct 5 ms 12636 KB Output is correct
12 Correct 41 ms 15440 KB Output is correct
13 Correct 8 ms 12632 KB Output is correct
14 Correct 5 ms 12636 KB Output is correct
15 Correct 951 ms 45648 KB Output is correct
16 Correct 18183 ms 46904 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 41 ms 2728 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 854 ms 860 KB Output is correct
30 Correct 2803 ms 30912 KB Output is correct
31 Correct 18418 ms 44376 KB Output is correct
32 Correct 18283 ms 44376 KB Output is correct
33 Correct 2675 ms 27476 KB Output is correct
34 Correct 18069 ms 41180 KB Output is correct
35 Correct 2700 ms 27488 KB Output is correct
36 Correct 17491 ms 41044 KB Output is correct
37 Correct 2777 ms 32340 KB Output is correct
38 Correct 18038 ms 44924 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 17547 ms 41168 KB Output is correct