Submission #962190

# Submission time Handle Problem Language Result Execution time Memory
962190 2024-04-13T08:45:00 Z NValchanov Wombats (IOI13_wombats) C++17
28 / 100
5681 ms 262144 KB
#include <bits/stdc++.h>
#include "wombats.h"

using namespace std;
typedef long long ll;

const ll MAXN = 5010;
const ll MAXM = 210;
const ll INF = 4e18 + 10;

ll n,m;
ll hor[MAXN][MAXM];
ll ver[MAXN][MAXM];
ll dp[MAXN][MAXM][MAXM];
ll ans_m1;

void init_dp(ll src)
{
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            dp[i][j][src] = INF;
        }
    }

    dp[0][src][src] = 0;

    for(int j = 1; j < m; j++)
    {
        dp[0][j][src] = min(dp[0][j][src], dp[0][j - 1][src] + hor[0][j - 1]);
    }

    for(int j = m - 2; j >= 0; j--)
    {
        dp[0][j][src] = min(dp[0][j][src], dp[0][j + 1][src] + hor[0][j]);
    }
}

void fill_dp(ll src)
{
    init_dp(src);

    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            dp[i][j][src] = min(dp[i][j][src], dp[i - 1][j][src] + ver[i - 1][j]);
        }
        for(int j = 1; j < m; j++)
        {
            dp[i][j][src] = min(dp[i][j][src], dp[i][j - 1][src] + hor[i][j - 1]);
        }
        for(int j = m - 2; j >= 0; j--)
        {
            dp[i][j][src] = min(dp[i][j][src], dp[i][j + 1][src] + hor[i][j]);
        }
    }
}

void calc()
{
    for(ll src = 0; src < m; src++)
    {
        fill_dp(src);
    }
}

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

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m - 1; j++)
        {
            hor[i][j] = H[i][j];
        }
    }

    for(int i = 0; i < n - 1; i++)
    {
        for(int j = 0; j < m; j++)
        {
            ver[i][j] = V[i][j];
        }
        if(m == 1)
            ans_m1 += ver[i][0];
    }

    calc();
}

void changeH(int i, int j, int w) /// change path from x;y to x;y + 1
{
    if(m == 1)
    {
        assert(false);
    }

    hor[i][j] = w;
    calc();
}

void changeV(int i, int j, int w) /// change path from x;y to x + 1;y
{
    if(m == 1)
    {
        ll new_change = w - ver[i][j];
        ans_m1 += new_change;
        ver[i][j] = w;
        return;
    }

    ver[i][j] = w;
    calc();
}

int escape(int from, int to) /// escape from (0;V1) to (N-1;V2)
{
    if(m == 1)
    {
        assert(from  + to == 0);
        return ans_m1;
    }

    return dp[n - 1][to][from];
}
/**
3 4
0 2 5
7 1 1
0 4 0
0 0 0 2
0 3 4 7
5
3 2 1
3 3 3
2 0 0 5
1 1 1 6
3 2 1
*/

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 Runtime error 40 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 55 ms 13648 KB Output is correct
12 Correct 2 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1188 ms 41876 KB Output is correct
2 Correct 1167 ms 42072 KB Output is correct
3 Correct 1203 ms 41876 KB Output is correct
4 Correct 1140 ms 41884 KB Output is correct
5 Correct 1153 ms 41888 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 5681 ms 41876 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1204 ms 41880 KB Output is correct
2 Correct 1180 ms 42072 KB Output is correct
3 Correct 1233 ms 41884 KB Output is correct
4 Correct 1171 ms 41880 KB Output is correct
5 Correct 1193 ms 41876 KB Output is correct
6 Correct 262 ms 255312 KB Output is correct
7 Correct 276 ms 255340 KB Output is correct
8 Correct 268 ms 255364 KB Output is correct
9 Correct 297 ms 256560 KB Output is correct
10 Correct 32 ms 246728 KB Output is correct
11 Correct 36 ms 246608 KB Output is correct
12 Correct 86 ms 247636 KB Output is correct
13 Correct 32 ms 246608 KB Output is correct
14 Correct 32 ms 246612 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12632 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 2 ms 12636 KB Output is correct
24 Correct 2 ms 12636 KB Output is correct
25 Correct 57 ms 14604 KB Output is correct
26 Correct 3 ms 12636 KB Output is correct
27 Correct 5540 ms 43744 KB Output is correct
28 Runtime error 97 ms 262144 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1169 ms 41880 KB Output is correct
2 Correct 1138 ms 41872 KB Output is correct
3 Correct 1224 ms 41876 KB Output is correct
4 Correct 1186 ms 43676 KB Output is correct
5 Correct 1187 ms 41880 KB Output is correct
6 Correct 260 ms 259420 KB Output is correct
7 Correct 261 ms 259320 KB Output is correct
8 Correct 267 ms 259320 KB Output is correct
9 Correct 292 ms 257876 KB Output is correct
10 Correct 35 ms 248656 KB Output is correct
11 Correct 36 ms 248688 KB Output is correct
12 Correct 83 ms 252244 KB Output is correct
13 Correct 34 ms 248660 KB Output is correct
14 Correct 32 ms 250704 KB Output is correct
15 Runtime error 170 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -