답안 #1074108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074108 2024-08-25T08:01:49 Z mindiyak 웜뱃 (IOI13_wombats) C++14
55 / 100
20000 ms 34004 KB
#include "wombats.h"
#include <vector>
#include <iostream>
#include <queue>

typedef long long ll;
#define F first
#define S second

using namespace std;

int H[5000][200];
int V[5000][200];
int R,C; 
int sum = 0;
int dp[205][205];
int need = 0;

void calc2(int V1){
    priority_queue<pair<int,pair<int,int>>> pq;

    pq.push({0,{0,V1}});
    int dis[R+5][C+5];
    int vis[R+5][C+5];

    for(int i=0;i<R+5;i++)for(int j=0;j<C+5;j++)dis[i][j] = 2e9;
    for(int i=0;i<R+5;i++)for(int j=0;j<C+5;j++)vis[i][j] = 0;

    dis[0][V1] = 0;

    while(!pq.empty()){
        int y = pq.top().S.F;
        int x = pq.top().S.S;
        pq.pop();

        if(vis[y][x])continue;
        vis[y][x] = 1;

        if(x > 0 && (dis[y][x] + H[y][x-1] < dis[y][x-1])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x-1] << " L\n";
            dis[y][x-1] = dis[y][x] + H[y][x-1];
            pq.push({-dis[y][x-1],{y,x-1}});
        }

        if(x < (C-1) && (dis[y][x] + H[y][x] < dis[y][x+1])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x] << " R\n";
            dis[y][x+1] = dis[y][x] + H[y][x];
            pq.push({-dis[y][x+1],{y,x+1}});
        }

        if(y < (R-1) && (dis[y][x] + V[y][x] < dis[y+1][x])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << V[y][x] << " D\n";
            dis[y+1][x] = dis[y][x] + V[y][x];
            pq.push({-dis[y+1][x],{y+1,x}});
        }
    }

    // for(int i=0;i<R;i++){
    //     for(int j=0;j<C;j++){
    //         cerr << dis[i][j] << " ";
    //     }cerr << endl;
    // }cerr << endl;

    for(int i=0;i<C+5;i++)dp[V1][i] = dis[R-1][i];
}

void calibrate(){
    if(C==1)return;
    need = 0;
    for(int i=0;i<C+5;i++)calc2(i);
}

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];
    for(int i=0;i<5000;i++)for(int j=0;j<200;j++)V[i][j] = v[i][j];
    for(int i=0;i<5000;i++)for(int j=0;j<200;j++)sum += V[i][j];

    need = 1;
}

void changeH(int P, int Q, int W) {
    H[P][Q] = W;
    need = 1;
}

void changeV(int P, int Q, int W) {
    sum -= V[P][Q];
    sum += W;
    V[P][Q] = W;
    need = 1;
}

int escape(int V1, int V2) {
    if(C == 1){
        return sum;
    }
    if(true){
        if(need == 1)calibrate();
        return dp[V1][V2];
    }
    priority_queue<pair<int,pair<int,int>>> pq;

    pq.push({0,{0,V1}});
    int dis[5005][205];
    int vis[5005][205];

    for(int i=0;i<5005;i++)for(int j=0;j<205;j++)dis[i][j] = 2e9;
    for(int i=0;i<5005;i++)for(int j=0;j<205;j++)vis[i][j] = 0;

    dis[0][V1] = 0;

    while(!pq.empty()){
        int y = pq.top().S.F;
        int x = pq.top().S.S;
        pq.pop();

        if(vis[y][x])continue;
        vis[y][x] = 1;

        if(x > 0 && (dis[y][x] + H[y][x-1] < dis[y][x-1])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x-1] << " L\n";
            dis[y][x-1] = dis[y][x] + H[y][x-1];
            pq.push({-dis[y][x-1],{y,x-1}});
        }

        if(x < (C-1) && (dis[y][x] + H[y][x] < dis[y][x+1])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x] << " R\n";
            dis[y][x+1] = dis[y][x] + H[y][x];
            pq.push({-dis[y][x+1],{y,x+1}});
        }

        if(y < (R-1) && (dis[y][x] + V[y][x] < dis[y+1][x])){
            // cerr << x << "," << y << " " << dis[y][x] << " " << V[y][x] << " D\n";
            dis[y+1][x] = dis[y][x] + V[y][x];
            pq.push({-dis[y+1][x],{y+1,x}});
        }
    }

    // for(int i=0;i<R;i++){
    //     for(int j=0;j<C;j++){
    //         cerr << dis[i][j] << " ";
    //     }cerr << endl;
    // }cerr << endl;

    return dis[R-1][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;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14172 KB Output is correct
2 Correct 5 ms 14232 KB Output is correct
3 Correct 57 ms 14900 KB Output is correct
4 Correct 5 ms 14172 KB Output is correct
5 Correct 8 ms 12212 KB Output is correct
6 Correct 5 ms 8284 KB Output is correct
7 Correct 5 ms 8284 KB Output is correct
8 Correct 6 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 7 ms 8124 KB Output is correct
3 Correct 4 ms 8284 KB Output is correct
4 Correct 10 ms 8124 KB Output is correct
5 Correct 10 ms 8284 KB Output is correct
6 Correct 10 ms 8284 KB Output is correct
7 Correct 4 ms 11864 KB Output is correct
8 Correct 7 ms 11864 KB Output is correct
9 Correct 6 ms 8116 KB Output is correct
10 Correct 7 ms 8284 KB Output is correct
11 Correct 43 ms 14164 KB Output is correct
12 Correct 6 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 632 ms 12212 KB Output is correct
2 Correct 9569 ms 8812 KB Output is correct
3 Correct 6273 ms 12220 KB Output is correct
4 Correct 6798 ms 12124 KB Output is correct
5 Correct 6461 ms 12148 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 3 ms 9940 KB Output is correct
8 Correct 5 ms 9820 KB Output is correct
9 Correct 4106 ms 12208 KB Output is correct
10 Correct 6 ms 11868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5327 ms 16668 KB Output is correct
2 Correct 5147 ms 16624 KB Output is correct
3 Correct 5746 ms 16836 KB Output is correct
4 Correct 5740 ms 17920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 621 ms 8600 KB Output is correct
2 Correct 9524 ms 8968 KB Output is correct
3 Correct 6238 ms 10584 KB Output is correct
4 Correct 6817 ms 10512 KB Output is correct
5 Correct 6432 ms 10524 KB Output is correct
6 Correct 5362 ms 16628 KB Output is correct
7 Correct 5044 ms 16732 KB Output is correct
8 Correct 5008 ms 16728 KB Output is correct
9 Correct 5135 ms 18128 KB Output is correct
10 Correct 4 ms 14168 KB Output is correct
11 Correct 7 ms 14172 KB Output is correct
12 Correct 42 ms 16884 KB Output is correct
13 Correct 4 ms 14172 KB Output is correct
14 Correct 5 ms 14024 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 6 ms 11864 KB Output is correct
19 Correct 3 ms 11868 KB Output is correct
20 Correct 4 ms 11968 KB Output is correct
21 Correct 4 ms 11864 KB Output is correct
22 Correct 4 ms 11868 KB Output is correct
23 Correct 5 ms 11868 KB Output is correct
24 Correct 4 ms 11868 KB Output is correct
25 Correct 43 ms 14228 KB Output is correct
26 Correct 5 ms 11868 KB Output is correct
27 Correct 4093 ms 12284 KB Output is correct
28 Execution timed out 20071 ms 26540 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 12124 KB Output is correct
2 Correct 9546 ms 12280 KB Output is correct
3 Correct 6321 ms 12132 KB Output is correct
4 Correct 6682 ms 12132 KB Output is correct
5 Correct 6432 ms 12144 KB Output is correct
6 Correct 5072 ms 16752 KB Output is correct
7 Correct 5004 ms 16668 KB Output is correct
8 Correct 4997 ms 16668 KB Output is correct
9 Correct 5085 ms 17440 KB Output is correct
10 Correct 4 ms 14168 KB Output is correct
11 Correct 4 ms 14172 KB Output is correct
12 Correct 47 ms 16780 KB Output is correct
13 Correct 4 ms 14168 KB Output is correct
14 Correct 4 ms 14168 KB Output is correct
15 Execution timed out 20050 ms 34004 KB Time limit exceeded
16 Halted 0 ms 0 KB -