Submission #777063

# Submission time Handle Problem Language Result Execution time Memory
777063 2023-07-08T15:04:08 Z caganyanmaz Wombats (IOI13_wombats) C++17
100 / 100
5719 ms 183568 KB
#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;

constexpr static int MXR = 5000;
constexpr static int MXC = 200;
constexpr static int BLOCK = 10;
constexpr static int MXST = 1030;
constexpr static int INF = 2e9 + 1;
int r, c, n;
int h[MXR][MXC], v[MXR][MXC];
int st[MXST][MXC][MXC];


void update_block(int i, int start);
void merge_blocks(int res, int a, int b);

void build(int ll, int rr, int index)
{
        if (ll + 1 == rr)
        {
                update_block(index, ll);
                return;
        }
        int m = ll+rr>>1;
        build(ll, m, index<<1);
        build(m, rr, (index<<1)|1);
        merge_blocks(index, index<<1, (index<<1)|1);
}

void update(int ll, int rr, int index, int i)
{
        if (rr == i+1 && ll == i)
        {
                update_block(index, i);
                return;
        }
        if (i >= rr || ll > i)
                return;
        int m = ll+rr>>1;
        update(ll, m, index<<1, i);
        update(m, rr, (index<<1)|1, i);
        merge_blocks(index, index<<1, (index<<1)|1);
}

void init(int R, int C, int H[MXR][MXC], int V[MXR][MXC])
{
        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];
        n = r / BLOCK;
        if (r % BLOCK)
                n++;
        build(0, n, 1);
}

void changeH(int P, int Q, int W)
{
        h[P][Q] = W;
        update(0, n, 1, P/BLOCK);
        if (P/BLOCK)
                update(0, n, 1, (P/BLOCK)-1);
}

void changeV(int P, int Q, int W)
{
        v[P][Q] = W;
        update(0, n, 1, P/BLOCK);
}

int escape(int V1, int V2)
{
        return st[1][V1][V2];
}

void update_block(int x, int start)
{
        int ss = start * BLOCK;
        int ee = min((start+1) * BLOCK, r-1);
        for (int i = 0; i < c; i++)
        {
                int prefix = 0;
                for (int j = i; j < c; j++)
                {
                        st[x][i][j] = st[x][j][i] = prefix;
                        prefix += h[ss][j];
                }
        }
        for (int i = ss+1; i <= ee; i++)
        {
                for (int j = 0; j < c; j++)
                {
                        for (int k = 0; k < c; k++)
                                st[x][j][k] += v[i-1][k];
                        for (int k = 1; k < c; k++)
                                st[x][j][k] = min(st[x][j][k], st[x][j][k-1] + h[i][k-1]);
                        for (int k = c-2; k >= 0; k--)
                                st[x][j][k] = min(st[x][j][k], st[x][j][k+1] + h[i][k]);
                }
        }
}

int opt[MXC][MXC];
void merge_blocks(int res, int a, int b)
{
        for (int i = c-1; i >= 0; i--)
        {
                for (int j = i; j < c; j++)
                {
                        int ss = (i==j) ? 0 : opt[i][j-1];
                        int ee = (i==j) ? c-1 : opt[i+1][j];
                        opt[i][j] = ss;
                        st[res][i][j] = st[a][i][ss] + st[b][ss][j];
                        for (int k = ss+1; k <= ee; k++)
                        {
                                int val = st[a][i][k] + st[b][k][j];
                                if (st[res][i][j] > val)
                                {
                                        opt[i][j] = k;
                                        st[res][i][j] = val;
                                }
                        }
                }
        }
        for (int j = c-1; j >= 0; j--)
        {
                for (int i = j+1; i < c; i++)
                {
                        opt[i][j] = opt[i-1][j];
                        st[res][i][j] = st[a][i][opt[i][j]] + st[b][opt[i][j]][j];
                        for (int k = opt[i][j]+1; k <= opt[i][j+1]; k++)
                        {
                                int val = st[a][i][k] + st[b][k][j];
                                if (st[res][i][j] > val)
                                {
                                        opt[i][j] = k;
                                        st[res][i][j] = val;
                                }
                        }
                }
        }
}

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 'void build(int, int, int)':
wombats.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         int m = ll+rr>>1;
      |                 ~~^~~
wombats.cpp: In function 'void update(int, int, int, int)':
wombats.cpp:40:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int m = ll+rr>>1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12372 KB Output is correct
2 Correct 5 ms 12372 KB Output is correct
3 Correct 76 ms 15180 KB Output is correct
4 Correct 5 ms 12500 KB Output is correct
5 Correct 6 ms 12396 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 54 ms 1364 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 2396 KB Output is correct
2 Correct 93 ms 2256 KB Output is correct
3 Correct 182 ms 2276 KB Output is correct
4 Correct 104 ms 2260 KB Output is correct
5 Correct 126 ms 2264 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 665 ms 2272 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 20948 KB Output is correct
2 Correct 8 ms 21056 KB Output is correct
3 Correct 9 ms 21056 KB Output is correct
4 Correct 35 ms 22388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 2216 KB Output is correct
2 Correct 94 ms 2260 KB Output is correct
3 Correct 194 ms 2280 KB Output is correct
4 Correct 103 ms 2272 KB Output is correct
5 Correct 122 ms 2264 KB Output is correct
6 Correct 10 ms 20948 KB Output is correct
7 Correct 9 ms 21076 KB Output is correct
8 Correct 9 ms 21040 KB Output is correct
9 Correct 40 ms 22472 KB Output is correct
10 Correct 5 ms 12372 KB Output is correct
11 Correct 7 ms 12372 KB Output is correct
12 Correct 59 ms 15176 KB Output is correct
13 Correct 5 ms 12476 KB Output is correct
14 Correct 6 ms 12372 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 440 KB Output is correct
25 Correct 55 ms 2736 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 660 ms 2348 KB Output is correct
28 Correct 1502 ms 102128 KB Output is correct
29 Correct 1321 ms 84224 KB Output is correct
30 Correct 1372 ms 84248 KB Output is correct
31 Correct 1383 ms 103852 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 2268 KB Output is correct
2 Correct 94 ms 2264 KB Output is correct
3 Correct 181 ms 2260 KB Output is correct
4 Correct 103 ms 2280 KB Output is correct
5 Correct 125 ms 2264 KB Output is correct
6 Correct 9 ms 20928 KB Output is correct
7 Correct 9 ms 21076 KB Output is correct
8 Correct 9 ms 21060 KB Output is correct
9 Correct 36 ms 22432 KB Output is correct
10 Correct 5 ms 12372 KB Output is correct
11 Correct 5 ms 12480 KB Output is correct
12 Correct 59 ms 15212 KB Output is correct
13 Correct 5 ms 12372 KB Output is correct
14 Correct 5 ms 12480 KB Output is correct
15 Correct 1855 ms 182260 KB Output is correct
16 Correct 5570 ms 183568 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 54 ms 2804 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 654 ms 2364 KB Output is correct
30 Correct 1512 ms 102140 KB Output is correct
31 Correct 5719 ms 180996 KB Output is correct
32 Correct 5536 ms 180948 KB Output is correct
33 Correct 1323 ms 84284 KB Output is correct
34 Correct 5071 ms 150048 KB Output is correct
35 Correct 1378 ms 84300 KB Output is correct
36 Correct 5349 ms 149736 KB Output is correct
37 Correct 1380 ms 103836 KB Output is correct
38 Correct 5171 ms 181664 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 5363 ms 150064 KB Output is correct