Submission #97588

# Submission time Handle Problem Language Result Execution time Memory
97588 2019-02-17T10:32:57 Z georgerapeanu Wombats (IOI13_wombats) C++11
37 / 100
20000 ms 20404 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];
            sum += h[i][j];
            sum += 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:69:17: warning: unused variable 'cost' [-Wunused-variable]
             int cost = q.front().second;
                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 13 ms 12032 KB Output is correct
3 Correct 101 ms 14368 KB Output is correct
4 Correct 15 ms 12032 KB Output is correct
5 Correct 14 ms 12032 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 2360 ms 1660 KB Output is correct
12 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 768 KB Output is correct
2 Correct 30 ms 768 KB Output is correct
3 Correct 34 ms 768 KB Output is correct
4 Correct 41 ms 768 KB Output is correct
5 Correct 30 ms 768 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 39 ms 768 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 850 ms 19920 KB Output is correct
2 Correct 835 ms 19840 KB Output is correct
3 Correct 1010 ms 20048 KB Output is correct
4 Execution timed out 20051 ms 20404 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 34 ms 684 KB Output is correct
2 Correct 29 ms 768 KB Output is correct
3 Correct 32 ms 896 KB Output is correct
4 Correct 33 ms 768 KB Output is correct
5 Correct 32 ms 768 KB Output is correct
6 Correct 819 ms 19924 KB Output is correct
7 Correct 706 ms 19832 KB Output is correct
8 Correct 727 ms 20020 KB Output is correct
9 Execution timed out 20028 ms 20400 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 768 KB Output is correct
2 Correct 31 ms 768 KB Output is correct
3 Correct 36 ms 888 KB Output is correct
4 Correct 31 ms 768 KB Output is correct
5 Correct 37 ms 768 KB Output is correct
6 Correct 751 ms 19988 KB Output is correct
7 Correct 756 ms 19936 KB Output is correct
8 Correct 936 ms 20116 KB Output is correct
9 Execution timed out 20066 ms 20400 KB Time limit exceeded
10 Halted 0 ms 0 KB -