Submission #97587

# Submission time Handle Problem Language Result Execution time Memory
97587 2019-02-17T10:31:51 Z georgerapeanu Wombats (IOI13_wombats) C++11
0 / 100
20000 ms 20456 KB
#include "wombats.h"
#include <queue>
#include <algorithm>

using namespace std;

int n,m;
int h[5000][200];
int v[5000][200];

int dp[5000][200];

int sum = 0;

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n = R;
    m = C;

    for(int i = 0;i < R;i++){
        for(int j = 0; j < C;j++){
            h[i][j] = H[i][j];
            v[i][j] = V[i][j];
        }
    }
}

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

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

int escape(int V1, int V2) {
    if(m == 1){
        return sum;
    }

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            dp[i][j] = 1 << 28;
        }
    }        

    dp[0][V1] = 0;

    for(int i = V1 - 1;i >= 0;i--){
        dp[0][i] = dp[0][i + 1] + h[0][i];
    }

    for(int i = V1 + 1;i < m;i++){
        dp[0][i] = dp[0][i - 1] + h[0][i - 1];
    }

    for(int i = 1;i < n;i++){
        queue< pair<int,int> > q;
        for(int j = 0;j < m;j++){
            dp[i][j] = dp[i - 1][j] + v[i - 1][j];
            q.push({j,dp[i][j]});
        }

        while(!q.empty()){
            int x = q.front().first;
            int cost = q.front().second;
            q.pop();

            if(x > 0 && dp[i][x - 1] > dp[i][x] + h[i][x - 1]){
                dp[i][x - 1] = dp[i][x] + h[i][x - 1];
                q.push({x - 1,dp[i][x - 1]});
            }

            if(x + 1 < m && dp[i][x + 1] > dp[i][x] + h[i][x]){
                dp[i][x + 1] = dp[i][x] + h[i][x];
                q.push({x + 1,dp[i][x + 1]});
            }
        }
    }

    return dp[n - 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]
  int res;
      ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:67:17: warning: unused variable 'cost' [-Wunused-variable]
             int cost = q.front().second;
                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12032 KB Output is correct
2 Incorrect 13 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 784 KB Output is correct
2 Correct 39 ms 768 KB Output is correct
3 Correct 41 ms 888 KB Output is correct
4 Correct 41 ms 768 KB Output is correct
5 Correct 29 ms 768 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Incorrect 2 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 817 ms 20040 KB Output is correct
2 Correct 900 ms 19948 KB Output is correct
3 Correct 759 ms 19840 KB Output is correct
4 Execution timed out 20029 ms 20456 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 35 ms 768 KB Output is correct
2 Correct 29 ms 768 KB Output is correct
3 Correct 38 ms 768 KB Output is correct
4 Correct 33 ms 888 KB Output is correct
5 Correct 35 ms 768 KB Output is correct
6 Correct 927 ms 19960 KB Output is correct
7 Correct 816 ms 20088 KB Output is correct
8 Correct 822 ms 20092 KB Output is correct
9 Execution timed out 20061 ms 20300 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 768 KB Output is correct
2 Correct 30 ms 768 KB Output is correct
3 Correct 39 ms 768 KB Output is correct
4 Correct 34 ms 768 KB Output is correct
5 Correct 32 ms 768 KB Output is correct
6 Correct 853 ms 19948 KB Output is correct
7 Correct 870 ms 19932 KB Output is correct
8 Correct 784 ms 19832 KB Output is correct
9 Execution timed out 20076 ms 20384 KB Time limit exceeded
10 Halted 0 ms 0 KB -