답안 #1093255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093255 2024-09-26T11:49:29 Z Wansur 웜뱃 (IOI13_wombats) C++17
100 / 100
13841 ms 134588 KB
#include <bits/stdc++.h>
#include "wombats.h"
#define ent '\n'

using namespace std;
typedef long long ll;

struct asd{
    int l, r, t[202][202], opt[202][202];
    asd(){
        l = r = 0;
        for(int i=0;i<202;i++){
            for(int j=0;j<202;j++){
                opt[i][j] = 200;
                t[i][j] = 1e9;
            }
        }
    }
};

int h[5050][205], v[5050][205];
int dp[5050][205];
int n, m, k, N;

asd merge(asd a, asd b){
    asd ans;
    ans.l = a.l, ans.r = b.r;
    for(int i = 0; i < m; i++){
        for(int j = m - 1; j >= 0; j--){
            int l = 0, r = min(ans.opt[i][j+1], m - 1);
            if(i > 0) l = ans.opt[i-1][j];
            for(int k = l; k <= r; k++){
                int val = a.t[i][k] + b.t[k][j] + v[a.r][k];
                if(val < ans.t[i][j]){
                    ans.t[i][j] = val;
                    ans.opt[i][j] = k;
                }
            }
        }
    }
    return ans;
}

asd calc(int l, int r){
    asd ans;
    ans.l = l, ans.r = r;
    for(int x=0;x<m;x++){
        for(int i=l;i<=r;i++){
            for(int j=0;j<m;j++)
                dp[i][j] = 1e9;
        }
        dp[l][x] = 0;
        for(int i=l;i<r;i++){
            for(int j=m-2;j>=0;j--){
                dp[i][j] = min(dp[i][j], dp[i][j+1] + h[i][j]);
            }
            for(int j=1;j<m;j++){
                dp[i][j] = min(dp[i][j], dp[i][j-1] + h[i][j-1]);
            }
            for(int j=0;j<m;j++){
                dp[i+1][j] = dp[i][j] + v[i][j];
            }
        }
        for(int j=m-2;j>=0;j--){
            dp[r][j] = min(dp[r][j], dp[r][j+1] + h[r][j]);
        }
        for(int j=1;j<m;j++){
            dp[r][j] = min(dp[r][j], dp[r][j-1] + h[r][j-1]);
        }
        for(int y=0;y<m;y++){
            ans.t[x][y] = dp[r][y];
        }
    }
    return ans;
}

asd t[250], a[66];

void build(int v, int tl, int tr){
    if(tl == tr){
        t[v] = a[tl];
    }
    else{
        int mid = tl + tr >> 1;
        build(v*2, tl, mid);
        build(v*2+1, mid+1, tr);
        if(v != 1) t[v] = merge(t[v*2], t[v*2+1]);
    }
}

void upd(int v, int tl , int tr, int pos){
    if(tl == tr){
        t[v] = a[pos];
    }
    else{
        int mid = tl + tr >> 1;
        if(pos <= mid){
            upd(v*2, tl, mid, pos);
        }
        else{
            upd(v*2+1, mid+1, tr, pos);
        }
        if(v != 1) t[v] = merge(t[v*2], t[v*2+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;i++){
        for(int j=0;j<m-1;j++){
            h[i][j] = H[i][j];
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            v[i][j] = V[i][j];
        }
    }
    k = 83;
    for(int i=0;i<n;i+=k){
        int j = min(i + k - 1, n - 1);
        a[i / k] = calc(i, j);
        N = i / k;
    }
    build(1, 0 , N);
}

void changeH(int i, int j, int x){
    h[i][j] = x;
    a[i / k] = calc(i / k * k, min(n, (i + k) / k * k) - 1);
    upd(1, 0, N, i / k);
}

void changeV(int i, int j, int x){
    v[i][j] = x;
    a[i / k] = calc(i / k * k, min(n, (i + k) / k * k) - 1);
    upd(1, 0, N, i / k);
}

int escape(int vv, int u){
    if(N == 0) return a[0].t[vv][u];
    int ans = 1e9;
    for(int i=0;i<m;i++){
        ans = min(ans, t[2].t[vv][i] + t[3].t[i][u] + v[t[2].r][i]);
    }
    return ans;
}

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 'void build(int, int, int)':
wombats.cpp:84:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |         int mid = tl + tr >> 1;
      |                   ~~~^~~~
wombats.cpp: In function 'void upd(int, int, int, int)':
wombats.cpp:96:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   96 |         int mid = tl + tr >> 1;
      |                   ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 115708 KB Output is correct
2 Correct 260 ms 115836 KB Output is correct
3 Correct 300 ms 118608 KB Output is correct
4 Correct 298 ms 115752 KB Output is correct
5 Correct 280 ms 115648 KB Output is correct
6 Correct 49 ms 101460 KB Output is correct
7 Correct 48 ms 101460 KB Output is correct
8 Correct 47 ms 101484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 101456 KB Output is correct
2 Correct 45 ms 101456 KB Output is correct
3 Correct 48 ms 101456 KB Output is correct
4 Correct 50 ms 101720 KB Output is correct
5 Correct 47 ms 101716 KB Output is correct
6 Correct 48 ms 101716 KB Output is correct
7 Correct 48 ms 101712 KB Output is correct
8 Correct 45 ms 101724 KB Output is correct
9 Correct 45 ms 101544 KB Output is correct
10 Correct 47 ms 101716 KB Output is correct
11 Correct 82 ms 103960 KB Output is correct
12 Correct 51 ms 101712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 102492 KB Output is correct
2 Correct 618 ms 102480 KB Output is correct
3 Correct 550 ms 102484 KB Output is correct
4 Correct 564 ms 102272 KB Output is correct
5 Correct 622 ms 102420 KB Output is correct
6 Correct 51 ms 101460 KB Output is correct
7 Correct 49 ms 101456 KB Output is correct
8 Correct 48 ms 101484 KB Output is correct
9 Correct 2931 ms 102492 KB Output is correct
10 Correct 49 ms 101716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 123732 KB Output is correct
2 Correct 282 ms 123732 KB Output is correct
3 Correct 297 ms 123728 KB Output is correct
4 Correct 293 ms 125184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 102276 KB Output is correct
2 Correct 643 ms 102480 KB Output is correct
3 Correct 553 ms 102480 KB Output is correct
4 Correct 558 ms 102484 KB Output is correct
5 Correct 625 ms 102252 KB Output is correct
6 Correct 253 ms 123772 KB Output is correct
7 Correct 260 ms 123732 KB Output is correct
8 Correct 277 ms 123732 KB Output is correct
9 Correct 272 ms 125268 KB Output is correct
10 Correct 260 ms 116104 KB Output is correct
11 Correct 258 ms 115772 KB Output is correct
12 Correct 349 ms 118524 KB Output is correct
13 Correct 276 ms 115792 KB Output is correct
14 Correct 333 ms 115796 KB Output is correct
15 Correct 48 ms 101460 KB Output is correct
16 Correct 47 ms 101712 KB Output is correct
17 Correct 49 ms 101668 KB Output is correct
18 Correct 48 ms 101716 KB Output is correct
19 Correct 61 ms 101716 KB Output is correct
20 Correct 53 ms 101712 KB Output is correct
21 Correct 47 ms 101680 KB Output is correct
22 Correct 46 ms 101712 KB Output is correct
23 Correct 47 ms 101712 KB Output is correct
24 Correct 48 ms 101716 KB Output is correct
25 Correct 89 ms 104020 KB Output is correct
26 Correct 48 ms 101712 KB Output is correct
27 Correct 2950 ms 102736 KB Output is correct
28 Correct 3731 ms 127796 KB Output is correct
29 Correct 3662 ms 123904 KB Output is correct
30 Correct 3501 ms 123824 KB Output is correct
31 Correct 3684 ms 129620 KB Output is correct
32 Correct 47 ms 101712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 102392 KB Output is correct
2 Correct 614 ms 102492 KB Output is correct
3 Correct 549 ms 102432 KB Output is correct
4 Correct 557 ms 102264 KB Output is correct
5 Correct 607 ms 102452 KB Output is correct
6 Correct 258 ms 123728 KB Output is correct
7 Correct 251 ms 123732 KB Output is correct
8 Correct 303 ms 123852 KB Output is correct
9 Correct 279 ms 125264 KB Output is correct
10 Correct 259 ms 115796 KB Output is correct
11 Correct 279 ms 116048 KB Output is correct
12 Correct 297 ms 118612 KB Output is correct
13 Correct 285 ms 115792 KB Output is correct
14 Correct 255 ms 115644 KB Output is correct
15 Correct 1684 ms 133272 KB Output is correct
16 Correct 13841 ms 134588 KB Output is correct
17 Correct 49 ms 101456 KB Output is correct
18 Correct 44 ms 101536 KB Output is correct
19 Correct 47 ms 101460 KB Output is correct
20 Correct 44 ms 101712 KB Output is correct
21 Correct 52 ms 101712 KB Output is correct
22 Correct 48 ms 101712 KB Output is correct
23 Correct 46 ms 101584 KB Output is correct
24 Correct 43 ms 101716 KB Output is correct
25 Correct 54 ms 101716 KB Output is correct
26 Correct 47 ms 101724 KB Output is correct
27 Correct 81 ms 103960 KB Output is correct
28 Correct 46 ms 101664 KB Output is correct
29 Correct 2982 ms 102492 KB Output is correct
30 Correct 3565 ms 127864 KB Output is correct
31 Correct 13438 ms 132080 KB Output is correct
32 Correct 13739 ms 131928 KB Output is correct
33 Correct 3628 ms 123984 KB Output is correct
34 Correct 13593 ms 128068 KB Output is correct
35 Correct 3489 ms 123984 KB Output is correct
36 Correct 13249 ms 127824 KB Output is correct
37 Correct 3649 ms 129644 KB Output is correct
38 Correct 13597 ms 132788 KB Output is correct
39 Correct 52 ms 101588 KB Output is correct
40 Correct 13489 ms 128080 KB Output is correct