Submission #1074665

# Submission time Handle Problem Language Result Execution time Memory
1074665 2024-08-25T11:55:11 Z mindiyak Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 33876 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;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;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14168 KB Output is correct
2 Correct 4 ms 14172 KB Output is correct
3 Correct 41 ms 16832 KB Output is correct
4 Correct 4 ms 14168 KB Output is correct
5 Correct 4 ms 14168 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 6 ms 9820 KB Output is correct
3 Correct 3 ms 9840 KB Output is correct
4 Correct 5 ms 11868 KB Output is correct
5 Correct 3 ms 11868 KB Output is correct
6 Correct 4 ms 11868 KB Output is correct
7 Correct 4 ms 12000 KB Output is correct
8 Correct 4 ms 11972 KB Output is correct
9 Correct 4 ms 12120 KB Output is correct
10 Correct 4 ms 11868 KB Output is correct
11 Correct 42 ms 14284 KB Output is correct
12 Correct 4 ms 11868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 577 ms 12208 KB Output is correct
2 Correct 9062 ms 12508 KB Output is correct
3 Correct 5916 ms 12124 KB Output is correct
4 Correct 6478 ms 12216 KB Output is correct
5 Correct 6166 ms 12124 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3935 ms 12252 KB Output is correct
10 Correct 4 ms 11868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1025 ms 16948 KB Output is correct
2 Correct 1389 ms 16728 KB Output is correct
3 Correct 1020 ms 16732 KB Output is correct
4 Correct 1066 ms 18244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 582 ms 12124 KB Output is correct
2 Correct 9028 ms 12348 KB Output is correct
3 Correct 5949 ms 12212 KB Output is correct
4 Correct 6461 ms 12120 KB Output is correct
5 Correct 6173 ms 12212 KB Output is correct
6 Correct 1043 ms 16732 KB Output is correct
7 Correct 1398 ms 16792 KB Output is correct
8 Correct 1024 ms 16732 KB Output is correct
9 Correct 1086 ms 18100 KB Output is correct
10 Correct 4 ms 14172 KB Output is correct
11 Correct 4 ms 14020 KB Output is correct
12 Correct 41 ms 16984 KB Output is correct
13 Correct 4 ms 14172 KB Output is correct
14 Correct 4 ms 14172 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 10072 KB Output is correct
18 Correct 5 ms 11864 KB Output is correct
19 Correct 3 ms 11996 KB Output is correct
20 Correct 4 ms 11868 KB Output is correct
21 Correct 4 ms 11824 KB Output is correct
22 Correct 4 ms 11868 KB Output is correct
23 Correct 4 ms 11868 KB Output is correct
24 Correct 4 ms 11868 KB Output is correct
25 Correct 48 ms 14300 KB Output is correct
26 Correct 4 ms 11868 KB Output is correct
27 Correct 3922 ms 12256 KB Output is correct
28 Execution timed out 20062 ms 26524 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 574 ms 12120 KB Output is correct
2 Correct 9014 ms 12356 KB Output is correct
3 Correct 5964 ms 12120 KB Output is correct
4 Correct 6534 ms 12212 KB Output is correct
5 Correct 6173 ms 12208 KB Output is correct
6 Correct 1042 ms 16728 KB Output is correct
7 Correct 1434 ms 16728 KB Output is correct
8 Correct 1027 ms 16748 KB Output is correct
9 Correct 1057 ms 18100 KB Output is correct
10 Correct 4 ms 14168 KB Output is correct
11 Correct 4 ms 14172 KB Output is correct
12 Correct 41 ms 16976 KB Output is correct
13 Correct 4 ms 14168 KB Output is correct
14 Correct 5 ms 14172 KB Output is correct
15 Execution timed out 20019 ms 33876 KB Time limit exceeded
16 Halted 0 ms 0 KB -