답안 #790617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790617 2023-07-23T01:05:48 Z Ronin13 웜뱃 (IOI13_wombats) C++17
76 / 100
2051 ms 262144 KB
#include <bits/stdc++.h>
#include "wombats.h"
#define ll long long 
#define ull unsigned ll
#define f first
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 505;
int h[5000][200];
int v[5000][200];
int r, c;
int s;
struct node{
    //vector <int> h;
    vector <int> w;
    vector <vector <int> > cost;
    node(){
        cost.resize(c);
        for(int i = 0; i < c; i++)
        cost[i].resize(c);
        w.resize(c);
    }
    node(int c){
        cost.resize(c);
        for(int i = 0; i < c; i++)
        cost[i].resize(c);
        w.resize(c);
    }
}t[4 * nmax];


node b[nmax];
node merg(node a, node b){
    node c;
    c.w = b.w;
    int n = a.w.size();
    c.cost.resize(n);
    vector <vector <int> > opt;
    opt.resize(n);
    for(int i= 0; i < n; i++)
        c.cost[i].resize(n), opt[i].resize(n);
    for(int i = 0; i < n; i++){
        int mn = 1e9 + 1, mni;
        for(int j= 0; j < n; j++){
            int val = a.cost[n - 1][j] + a.w[j] + b.cost[j][i];
            if(val < mn)
                mn = val, mni = j;
        }
        opt[n - 1][i] = mni, c.cost[n - 1][i] = mn;
    }
    for(int i = n - 2; i >= 0; i--){
        int mn = 1e9 + 1,mni;
        for(int j = 0; j < n; j++){
            int val = a.cost[i][j] + a.w[j] + b.cost[j][0];
            if(val < mn)
                mn = val, mni = j;
        }
        opt[i][0] = mni, c.cost[i][0] = mn;
        for(int j = 1; j <= n - 1; j++){
            int mn = 1e9 + 1, mni = j;
            for(int x = opt[i][j - 1]; x <= opt[i + 1][j]; x++){
                int val = a.cost[i][x] + a.w[x] + b.cost[x][j];
                if(val < mn)
                    mn = val, mni = x;
            }
            opt[i][j] = mni, c.cost[i][j] = mn;
        }
    }
    return c;
}

void update(int v, int l, int r, int pos, node a){
    if(l > pos || r < pos)
    return;
    if(l == r){
        t[v] = a;
        return;
    }
    int m = (l + r) / 2;
    update(2 * v, l, m, pos, a);
    update(2 * v + 1, m + 1, r, pos, a);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
}


void init(int R, int C, int H[5000][200], int V[5000][200]) {
    /* ... */
    r = R, c = C;
    for(int i = 0; i < 5000; i++){
        for(int j = 0; j < 200; j++)
        h[i][j] = H[i][j], v[i][j] = V[i][j]; 
     
    }
    for(int i = 0; i < r; i++){
        node a = {c};
        for(int j = 0; j < c; j++)
            a.w[j] = V[i][j];
        for(int x = 0; x < c; x++){
            a.cost[x][x] = 0;
            for(int y = x + 1; y < c; ++y){
                a.cost[x][y] = a.cost[x][y - 1] + H[i][y - 1];
            }
            for(int y = x - 1; y >= 0; y--)
                a.cost[x][y] = a.cost[x][y + 1] + H[i][y];
        }
        if(i % 10 == 0)
            b[i / 10] = a;
        else b[i / 10] =  merg(b[i / 10], a);
        s = i / 10;
    }
    for(int i = 0; i <= 3 * s; i++)
        t[i] = {c};
    for(int i = 0; i <= s; i++)
        update(1, 0, s, i, b[i]);
    
}

void update_block(int o){
   // b[o] = a[o * 10];
    int xx = o * 10;
    for(int i = xx; i < min(r, xx + 10); i++){
        node a = {c};
        for(int j = 0; j < c; j++)
            a.w[j] = v[i][j];
        for(int x = 0; x < c; x++){
            a.cost[x][x] = 0;
            for(int y = x + 1; y < c; ++y){
                a.cost[x][y] = a.cost[x][y - 1] + h[i][y - 1];
            }
            for(int y = x - 1; y >= 0; y--)
                a.cost[x][y] = a.cost[x][y + 1] + h[i][y];
        }
        if(i % 10 == 0)
            b[i / 10] = a;
        else b[i / 10] =  merg(b[i / 10], a);
    }
    update(1, 0, s, o, b[o]);
}

void changeH(int p, int q, int w) {
    /* ... */
    h[p][q] = w;
    update_block(p / 10);
}

void changeV(int p, int q, int w) {
    /* ... */
    
    v[p][q] = w;
    
    update_block(p / 10);
}

int escape(int V1, int V2) {
    return t[1].cost[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;
      |      ^~~
wombats.cpp: In function 'node merg(node, node)':
wombats.cpp:61:19: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |         opt[i][0] = mni, c.cost[i][0] = mn;
wombats.cpp:52:23: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |         opt[n - 1][i] = mni, c.cost[n - 1][i] = mn;
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12244 KB Output is correct
2 Correct 13 ms 12360 KB Output is correct
3 Correct 66 ms 13940 KB Output is correct
4 Correct 13 ms 12244 KB Output is correct
5 Correct 13 ms 12336 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 5 ms 8148 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8204 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 5 ms 8276 KB Output is correct
5 Correct 5 ms 8276 KB Output is correct
6 Correct 5 ms 8276 KB Output is correct
7 Correct 5 ms 8276 KB Output is correct
8 Correct 5 ms 8276 KB Output is correct
9 Correct 5 ms 8324 KB Output is correct
10 Correct 7 ms 8276 KB Output is correct
11 Correct 58 ms 9316 KB Output is correct
12 Correct 5 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 10324 KB Output is correct
2 Correct 130 ms 10396 KB Output is correct
3 Correct 160 ms 10356 KB Output is correct
4 Correct 163 ms 10408 KB Output is correct
5 Correct 164 ms 10388 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 5 ms 8152 KB Output is correct
8 Correct 4 ms 8172 KB Output is correct
9 Correct 603 ms 10452 KB Output is correct
10 Correct 4 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16340 KB Output is correct
2 Correct 17 ms 16396 KB Output is correct
3 Correct 17 ms 16396 KB Output is correct
4 Correct 44 ms 17116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 10420 KB Output is correct
2 Correct 135 ms 10344 KB Output is correct
3 Correct 168 ms 10400 KB Output is correct
4 Correct 158 ms 10412 KB Output is correct
5 Correct 160 ms 10392 KB Output is correct
6 Correct 17 ms 16340 KB Output is correct
7 Correct 21 ms 16292 KB Output is correct
8 Correct 17 ms 16340 KB Output is correct
9 Correct 44 ms 17136 KB Output is correct
10 Correct 13 ms 12364 KB Output is correct
11 Correct 13 ms 12360 KB Output is correct
12 Correct 69 ms 13928 KB Output is correct
13 Correct 13 ms 12244 KB Output is correct
14 Correct 13 ms 12336 KB Output is correct
15 Correct 4 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8276 KB Output is correct
19 Correct 5 ms 8276 KB Output is correct
20 Correct 5 ms 8276 KB Output is correct
21 Correct 5 ms 8276 KB Output is correct
22 Correct 5 ms 8276 KB Output is correct
23 Correct 5 ms 8272 KB Output is correct
24 Correct 5 ms 8244 KB Output is correct
25 Correct 58 ms 9276 KB Output is correct
26 Correct 5 ms 8288 KB Output is correct
27 Correct 594 ms 10408 KB Output is correct
28 Correct 1807 ms 103972 KB Output is correct
29 Correct 1856 ms 86920 KB Output is correct
30 Correct 1847 ms 86996 KB Output is correct
31 Correct 1800 ms 105004 KB Output is correct
32 Correct 5 ms 8160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 10352 KB Output is correct
2 Correct 129 ms 10392 KB Output is correct
3 Correct 159 ms 10388 KB Output is correct
4 Correct 164 ms 10428 KB Output is correct
5 Correct 157 ms 10392 KB Output is correct
6 Correct 19 ms 16368 KB Output is correct
7 Correct 17 ms 16340 KB Output is correct
8 Correct 18 ms 16376 KB Output is correct
9 Correct 45 ms 17100 KB Output is correct
10 Correct 13 ms 12244 KB Output is correct
11 Correct 13 ms 12360 KB Output is correct
12 Correct 65 ms 13864 KB Output is correct
13 Correct 18 ms 12244 KB Output is correct
14 Correct 13 ms 12244 KB Output is correct
15 Runtime error 2051 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -