Submission #767166

# Submission time Handle Problem Language Result Execution time Memory
767166 2023-06-26T13:01:31 Z fatemetmhr Wombats (IOI13_wombats) C++17
12 / 100
53 ms 36300 KB
//  ~ Be Name Khoda ~  //

#include "wombats.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second

const int maxnR =  5002;
const int maxnt =  700;
const int maxnC =  202;
const int mod   =  2e9;
const int lim   =  10;

int n, m, h[maxnR][maxnC], v[maxnR][maxnC], chil[maxnt][2];
int dp[2][maxnC][maxnC], opt[maxnC][maxnC], newnode = 1;

struct __dp{
    int dp[maxnC][maxnC];

} seg[maxnt];

inline void comb(__dp *ret, int mid, const __dp &a, const __dp &b){
    for(int dim = -(m - 1); dim < m; dim++) for(int i = max(0, -dim); i < min(m, m - dim); i++){
        int j = dim + i;
        int l = (j ? opt[i][j - 1] : 0), r = (i + 1 < m ? opt[i + 1][j] : m - 1);
        ret->dp[i][j] = mod;
        for(int k = l; k <= r; k++){
            int val = a.dp[i][k] + b.dp[k][j] + v[mid - 1][k];
            if(val < ret->dp[i][j]){
                opt[i][j] = k;
                ret->dp[i][j] = val;
            }
        }
    }
}

inline void cre(__dp *a, int l, int r){
    for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
        dp[1][i][j] = mod;
    for(int i = 0; i < m; i++)
        dp[1][i][i] = 0;
    for(int j = l; j < r; j++) for(int x = 0; x < m; x++){
        int mn = mod;
        for(int i = 0; i < m; i++){
            dp[j & 1][x][i] = min(mn, dp[(j + 1) & 1][x][i] + (j ? v[j - 1][i] : 0));
            mn = dp[j & 1][x][i] + h[j][i];
        }
        mn = mod;
        for(int i = m - 1; i >= 0; i--){
            dp[j & 1][x][i] = min(mn, dp[j & 1][x][i]);
            if(i)
                mn = dp[j & 1][x][i] + h[j][i - 1];
            //cout << "check " << j << ' ' << x << ' ' << i << ' ' << dp[j & 1][x][i] << ' ' << mn << endl;
        }
    }
    for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
        a->dp[i][j] = dp[(r - 1) & 1][i][j];
}

void upd(int l, int r, int id, int v){
    int mid = (l + r) >> 1;
    if(id < mid && chil[v][0])
        upd(l, mid, id, chil[v][0]);
    if(id >= mid && chil[v][1])
        upd(mid, r, id, chil[v][1]);
    if(chil[v][0] && chil[v][1])
        comb(&seg[v], mid, seg[v * 2], seg[v * 2 + 1]);
    else
        cre(&seg[v], l, r);
}

int build(int l, int r){
    if(r - l != n && r - l <= lim)
        return 0;
    int v = newnode++;
    int mid = (l + r) >> 1;
    chil[v][0] = build(l, mid);
    chil[v][1] = build(mid, r);
    if(chil[v][0] && chil[v][1])
        comb(&seg[v], mid, seg[v * 2], seg[v * 2 + 1]);
    else
        cre(&seg[v], l, r);
    return v;
}


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; j++){
        h[i][j] = H[i][j];
        v[i][j] = V[i][j];
    }
    build(0, n);
}

void changeH(int p, int q, int w) {
    h[p][q] = w;
    upd(0, n, p, 1);
}

void changeV(int p, int q, int w) {
    v[p][q] = w;
    upd(0, n, p, 1);
}

int escape(int v1, int v2) {
    return seg[1].dp[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 Runtime error 24 ms 27788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 53 ms 2744 KB Output is correct
12 Correct 1 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 2224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 36300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 2132 KB Output isn't correct
2 Halted 0 ms 0 KB -