Submission #585306

# Submission time Handle Problem Language Result Execution time Memory
585306 2022-06-28T15:06:46 Z Dan4Life Wombats (IOI13_wombats) C++17
0 / 100
115 ms 262144 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
const int INF = (int)1e9;
int h[5002][202], v[5002][202], dp[5002][202]; bool ok;
pii segTree[1000], r_segTree[1000];
int ans[204][204], n, m;

inline int mir(int x){return m-x-1;}

pii combine(pii left, pii right){
    pii temp; temp.fi = left.fi+right.fi;
    temp.se = min(left.se, left.fi+right.se);
    return temp;
}

void update(int x, int val, int i, pii segTree[], int p=1, int l=0, int r=m-1){
    if(l==r){ segTree[p]={val,val+v[i][l]}; return; }
    int mid = (l+r)/2;
    if(x<=mid) update(x,val,i,segTree,p*2,l,mid);
    else update(x,val,i,segTree,p*2+1,mid+1,r);
    segTree[p] = combine(segTree[p*2], segTree[p*2+1]);
}

pii query(int i, int j, pii segTree[], int p=1, int l=0, int r=m-1){
    if(i>r or j<l or i>j) return {INF,INF};
    int mid = (l+r)/2;
    auto left = query(i,j,segTree,p*2,l,mid);
    auto right = query(i,j,segTree,p*2+1,mid+1,r);
    auto ans = left;
    if(ans.se>right.se) ans = right;
    return ans;
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n = R, m = C; ok = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(j<m-1) h[i][j] = H[i][j];
            if(i<n-1) v[i][j] = V[i][j];
        }
    }
}

void update(int V1){
    dp[0][V1] = 0;
    for(int x = V1-1; x>=0; x--) dp[0][x] = dp[0][x+1]+h[0][x];
    for(int x = V1+1; x<m; x++) dp[0][x] = dp[0][x-1]+h[0][x-1];
    for(int i = 1; i < n; i++){
        for(int j = 0; j < m; j++)
            update(j, dp[i-1][j], i-1, segTree),
            update(mir(j), dp[i-1][j], i-1, r_segTree);
        for(int j = 0; j < m; j++){
            int J = mir(j), J0 = mir(0); if(J0>J) swap(J0,J);
            dp[i][j] = min({dp[i-1][j]+v[i-1][j],
                query(j+1,m-1,segTree).se, query(J0,J,r_segTree).se});
        }
    }
    for(int i = 0; i < m; i++) ans[V1][i] = dp[n-1][i];
}

void changeH(int P, int Q, int W) {
    h[P][Q]=W; for(int i = 0; i < m; i++) update(i);
}

void changeV(int P, int Q, int W) {
    v[P][Q]=W; for(int i = 0; i < m; i++) update(i);
}

int escape(int V1, int V2) {
    if(ok) for(int i = 0; i < m; i++) update(i);
    ok=0; return ans[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 107 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 109 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 115 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 115 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -