Submission #962220

# Submission time Handle Problem Language Result Execution time Memory
962220 2024-04-13T09:13:04 Z serkanrashid Wombats (IOI13_wombats) C++14
0 / 100
26 ms 40024 KB
#include "wombats.h"
#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int x,y;
    long long dist;
    edge(){};
    edge(int xi, int yi, long long di)
    {
        x = xi;
        y = yi;
        dist = di;
    }
    bool operator<(const edge&ed) const
    {
        return dist>ed.dist;
    }
};

int r,c;
int h[5000][200],v[5000][200];
unsigned int d[5000][200],inf = -1;

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

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

int escape(int V1, int V2)
{
    memset(d,-1,sizeof(d));
    priority_queue<edge>q;
    d[0][V1] = 0;
    q.push({0,V1,0});
    edge e,nb;
    while(!q.empty())
    {
        e = q.top();
        q.pop();
        if(e.dist<=d[e.x][e.y])
        {
            ///LEFT
            nb = {0,0,inf};
            if(e.y>0) nb = {e.x,e.y-1,h[e.x][e.y-1]};
            if(nb.dist!=inf&&e.dist+nb.dist<d[nb.x][nb.y])
            {
                nb.dist += e.dist;
                d[nb.x][nb.y] = nb.dist;
                q.push(nb);
            }

            ///RIGHT
            nb = {0,0,inf};
            if(e.y<c-1) nb = {e.x,e.y+1,h[e.x][e.y]};
            if(nb.dist!=inf&&e.dist+nb.dist<d[nb.x][nb.y])
            {
                nb.dist += e.dist;
                d[nb.x][nb.y] = nb.dist;
                q.push(nb);
            }

            ///DOWN
            nb = {0,0,inf};
            if(e.x<r-1) nb = {e.x+1,e.y,v[e.x][e.y]};
            if(nb.dist!=inf&&e.dist+nb.dist<d[nb.x][nb.y])
            {
                nb.dist += e.dist;
                d[nb.x][nb.y] = nb.dist;
                q.push(nb);
            }
        }
    }
    cout << d[r-1][V2] << endl;
}

void init(int R, int C, int H[5000][200], int V[5000][200])
{
    r = R;
    c = C;
    for(int i=0;i<R;i++)
        for(int j=0;j<C-1;j++) h[i][j] = H[i][j];

    for(int i=0;i<R-1;i++)
        for(int j=0;j<C;j++) v[i][j] = V[i][j];

}

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 'int escape(int, int)':
wombats.cpp:82:1: warning: no return statement in function returning non-void [-Wreturn-type]
   82 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 29776 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 12892 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 21340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 40024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 21340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 21468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -