Submission #836020

# Submission time Handle Problem Language Result Execution time Memory
836020 2023-08-24T05:04:13 Z definitelynotmee Wombats (IOI13_wombats) C++17
16 / 100
20000 ms 10568 KB
//#include "grader.c"
#include"wombats.h"
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T>
using matrix = vector<vector<T>>;
const int INF = 1e9;

struct matriz{
    matrix<int> v;

    matriz(int n = 0, int val = INF){
        v = matrix<int>(n,vector<int>(n,val));
    }

    matriz operator*(matriz & other){
        const int n = v.size();
        matriz ret(n);
        
        auto solve =[&](int source, int l, int r, int optl, int optr, auto solve) -> void {
            if(r < l)
                return;
            
            int m = (l+r)>>1;

            int opt = optl;

            for (int i = optl+1; i <= optr; i++)
                opt = min(opt,i,[&](int a, int b){
                    return v[source][a]+other.v[a][m] < v[source][b]+other.v[b][m]; 
                });
            
            ret.v[source][m] = v[source][opt]+other.v[opt][m];
            
            solve(source,m+1,r,opt,optr,solve);
            solve(source,l,m-1,optl,opt,solve);
        };

        for(int i = 0; i < n; i++)
            solve(i,0,n-1,0,n-1,solve);
        

        // for(int i = 0; i < n; i++){
        //     for(int j = 0; j < n; j++){
        //         for(int k = 0; k < n; k++){
        //             ret.v[i][j] = min(v[i][k]+other.v[k][j], ret.v[i][j]);
        //         }
        //     }
        // }

        return ret;
    }
};

int n, m;

vector<matriz> inrow;
vector<matriz> nextrow;

matrix<int> hor;
matrix<int> ver;

void build_in_row(int linha){
    inrow[linha] = matriz(m,0);
    for(int j = 0; j < m; j++){
        int cur = 0;

        for(int k = j; k < m-1; k++){
            cur+=hor[linha][k];
            inrow[linha].v[j][k+1] = inrow[linha].v[k+1][j] = cur;
        }
    }
}

void build_next(int linha){
    matriz col(m);

    for(int i = 0; i < m; i++)
        col.v[i][i] = ver[linha][i];
    
    nextrow[linha] = inrow[linha]*col*
    inrow[linha+1];
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    // cerr << "ok" << endl;

    n = R;
    m = C;

    // cerr << n << ' ' << m << endl;
    hor = matrix<int>(n,vector<int>(m-1));
    ver = matrix<int>(n-1,vector<int>(m));
    // cerr << "ok" << endl;

    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];
        }
    }

    inrow = vector<matriz>(n,matriz(m,0));

    // cerr << "ok" << endl;

    for(int i = 0; i < n; i++){
        // cerr << i << endl;
        build_in_row(i);
    }

    nextrow = vector<matriz>(n-1,matriz(m,0));

    for(int i = 0; i < n-1; i++){
        // cerr << i << endl;
        build_next(i);
    }

}

void changeH(int P, int Q, int W) {
    // cerr << P << ' ' << Q << endl;
    hor[P][Q] = W;
    build_in_row(P);
    if(P != n-1)
        build_next(P);
    if(P != 0)
        build_next(P-1);
}

void changeV(int P, int Q, int W) {
    // cerr << P << ' ' << Q << endl;
    ver[P][Q] = W;
    build_next(P);
}

int escape(int V1, int V2) {
    // cerr << V1 << ' ' << V2 << endl;

    matriz resp = nextrow[0];

    for(int i = 1; i < n-1; i++){
        resp = resp*nextrow[i];
    }

    return resp.v[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]
   15 |  int res;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 136 ms 5476 KB Output is correct
2 Correct 199 ms 5488 KB Output is correct
3 Execution timed out 20016 ms 6192 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 37 ms 340 KB Output is correct
5 Correct 36 ms 440 KB Output is correct
6 Correct 38 ms 432 KB Output is correct
7 Correct 59 ms 444 KB Output is correct
8 Correct 36 ms 340 KB Output is correct
9 Correct 41 ms 432 KB Output is correct
10 Correct 34 ms 456 KB Output is correct
11 Execution timed out 20020 ms 1976 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1821 ms 9256 KB Output is correct
2 Correct 1427 ms 9140 KB Output is correct
3 Correct 1852 ms 9372 KB Output is correct
4 Correct 1858 ms 9332 KB Output is correct
5 Correct 1776 ms 9256 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1844 ms 9352 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 509 ms 10224 KB Output is correct
2 Correct 508 ms 10196 KB Output is correct
3 Correct 515 ms 10216 KB Output is correct
4 Execution timed out 20056 ms 10568 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1773 ms 9288 KB Output is correct
2 Correct 1433 ms 9132 KB Output is correct
3 Correct 1877 ms 9264 KB Output is correct
4 Correct 1801 ms 9252 KB Output is correct
5 Correct 1819 ms 9172 KB Output is correct
6 Correct 520 ms 10068 KB Output is correct
7 Correct 493 ms 10148 KB Output is correct
8 Correct 561 ms 10188 KB Output is correct
9 Execution timed out 20068 ms 10460 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1786 ms 9176 KB Output is correct
2 Correct 1448 ms 9076 KB Output is correct
3 Correct 1821 ms 9524 KB Output is correct
4 Correct 1782 ms 9256 KB Output is correct
5 Correct 1758 ms 9288 KB Output is correct
6 Correct 516 ms 10140 KB Output is correct
7 Correct 476 ms 10068 KB Output is correct
8 Correct 523 ms 10144 KB Output is correct
9 Execution timed out 20071 ms 10380 KB Time limit exceeded
10 Halted 0 ms 0 KB -