Submission #156761

# Submission time Handle Problem Language Result Execution time Memory
156761 2019-10-07T10:10:30 Z Alexa2001 Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 19908 KB
#include "wombats.h"
#include <bits/stdc++.h>

using namespace std;

const int B = 500, Cmax = 205, Rmax = 5005;
const int inf = 1e8;

int N, M, rm;
int h[Rmax][Cmax], v[Rmax][Cmax];


static void min_to(int &x, int y) { if(x > y) x = y ;}

static void rec(int a[], int p)
{
    int i;
    for(i=1; i<M; ++i)
        min_to(a[i], a[i-1] + h[p][i-1]);

    for(i=M-2; i>=0; --i)
        min_to(a[i], a[i+1] + h[p][i]);
}

struct matrix
{
    int a[Cmax][Cmax];

    void combine(matrix &A, matrix &B, int pos)
    {
        int i, j, k;

        for(i=0; i<M; ++i)
            for(j=0; j<M; ++j)
            {
                a[i][j] = inf;
                for(k=0; k<M; ++k)
                    min_to(a[i][j], A.a[i][k] + B.a[k][j] + v[pos][k]);
            }
    }

    void refresh(int bucket)
    {
        int i, j, k;

        for(i=0; i<M; ++i)
        {
            for(j=0; j<M; ++j)
                a[i][j] = (i==j ? 0 : inf);

            for(k = bucket * B; k < (bucket+1) * B && k < N; ++k)
            {
                rec(a[i], k);

                if(k + 1 < min(B * (bucket+1), N))
                    for(j=0; j<M; ++j)
                        a[i][j] += v[k][j];
            }
        }
    }
};


#define left_son (node<<1)
#define right_son ((node<<1)|1)
#define mid ((st+dr)>>1)

namespace aint
{
    matrix a[ (Rmax / B + 3) << 2];

    void update(int node, int st, int dr, int pos)
    {
        if(st == dr)
        {
            a[node].refresh(st);
            return;
        }

        if(pos <= mid) update(left_son, st, mid, pos);
            else update(right_son, mid+1, dr, pos);

        a[node].combine(a[left_son], a[right_son], (mid+1) * B - 1);
    }

    void build(int node, int st, int dr)
    {
        if(st == dr)
        {
            a[node].refresh(st);
            return;
        }

        build(left_son, st, mid);
        build(right_son, mid+1, dr);

        a[node].combine(a[left_son], a[right_son], (mid+1) * B - 1);
    }

    int get_answer(int start, int finish)
    {
        return a[1].a[start][finish];
    }
};


void init(int R, int C, int H[5000][200], int V[5000][200])
{
    N = R; M = C;
    rm = (N-1) / B;

    int i, j;
    for(i=0; i<N; ++i)
        for(j=0; j<M; ++j)
            h[i][j] = H[i][j], v[i][j] = V[i][j];

    aint::build(1, 0, rm);
}

void changeH(int P, int Q, int W)
{
    h[P][Q] = W;
    aint::update(1, 0, rm, P / B);
}

void changeV(int P, int Q, int W)
{
    v[P][Q] = W;
    aint::update(1, 0, rm, P / B);
}

int escape(int V1, int V2)
{
    return aint::get_answer(V1, 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;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12408 KB Output is correct
2 Correct 14 ms 12408 KB Output is correct
3 Correct 84 ms 13896 KB Output is correct
4 Correct 15 ms 12280 KB Output is correct
5 Correct 15 ms 12280 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 380 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 79 ms 1400 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 892 ms 780 KB Output is correct
2 Correct 485 ms 780 KB Output is correct
3 Correct 886 ms 888 KB Output is correct
4 Correct 879 ms 784 KB Output is correct
5 Correct 857 ms 888 KB Output is correct
6 Correct 2 ms 372 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2797 ms 788 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 16248 KB Output is correct
2 Correct 21 ms 16248 KB Output is correct
3 Correct 24 ms 16248 KB Output is correct
4 Correct 60 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 871 ms 784 KB Output is correct
2 Correct 476 ms 888 KB Output is correct
3 Correct 887 ms 760 KB Output is correct
4 Correct 870 ms 888 KB Output is correct
5 Correct 861 ms 824 KB Output is correct
6 Correct 22 ms 16248 KB Output is correct
7 Correct 20 ms 16248 KB Output is correct
8 Correct 24 ms 16248 KB Output is correct
9 Correct 60 ms 17144 KB Output is correct
10 Correct 14 ms 12284 KB Output is correct
11 Correct 14 ms 12408 KB Output is correct
12 Correct 84 ms 13944 KB Output is correct
13 Correct 15 ms 12280 KB Output is correct
14 Correct 14 ms 12280 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 508 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 79 ms 1400 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2791 ms 796 KB Output is correct
28 Correct 18231 ms 18400 KB Output is correct
29 Execution timed out 20102 ms 15316 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 888 ms 904 KB Output is correct
2 Correct 480 ms 760 KB Output is correct
3 Correct 884 ms 784 KB Output is correct
4 Correct 865 ms 788 KB Output is correct
5 Correct 866 ms 892 KB Output is correct
6 Correct 22 ms 16248 KB Output is correct
7 Correct 21 ms 16248 KB Output is correct
8 Correct 24 ms 16248 KB Output is correct
9 Correct 60 ms 17016 KB Output is correct
10 Correct 14 ms 12408 KB Output is correct
11 Correct 16 ms 12280 KB Output is correct
12 Correct 88 ms 13944 KB Output is correct
13 Correct 14 ms 12280 KB Output is correct
14 Correct 14 ms 12280 KB Output is correct
15 Correct 1322 ms 19524 KB Output is correct
16 Execution timed out 20034 ms 19908 KB Time limit exceeded
17 Halted 0 ms 0 KB -