Submission #585407

# Submission time Handle Problem Language Result Execution time Memory
585407 2022-06-28T19:57:54 Z Dan4Life Wombats (IOI13_wombats) C++17
0 / 100
20000 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;
struct node{ int sum, pref, suff; } segTree[800], normal;
int ans[204][204], n, m;

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

node combine(node left, node right){
    node temp; temp.sum = left.sum+right.sum;
    temp.pref = min(left.pref, left.sum+right.pref);
    temp.suff = min(right.suff, right.sum+left.suff);
    return temp;
}

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

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

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n = R, m = C; ok = 1; normal.sum=normal.pref=normal.suff=INF;
    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 i = 0; i < 800; i++) 
        segTree[i].sum=segTree[i].pref=segTree[i].suff=INF;
    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, h[i][(j==m?j-1:j)], i-1);
        }
        //o--o---o--o--o
        //|  |   |  |  |
        //o--o---o--o--o
        for(int j = 0; j < m; j++)
            dp[i][j] = min({dp[i-1][j]+v[i-1][j],
                query(j,m-1).pref, query(0,j).suff});
    }
    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 128 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 20031 ms 876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 20064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 20037 ms 956 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 20087 ms 880 KB Time limit exceeded
2 Halted 0 ms 0 KB -