답안 #16753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16753 2015-09-18T12:19:47 Z CodingBug 웜뱃 (IOI13_wombats) C++
28 / 100
537 ms 262144 KB
#include "wombats.h"
#include <algorithm>
#define R 5000
#define C 200
#define INF 1000000000

using namespace std;

struct Node{
    int d[C][C];
    Node *chi[2];
} *rt;

int r,c;
int h[R][C],v[R][C];

void dp(int d[C][C],int s,int e){
    int i,j,k;

    for(k=0;k<c;k++){
        for(j=0;j<c;j++) d[k][j]=(k==j ? 0 : INF+1);

        for(i=s;i<e;i++){
            for(j=1;j<c;j++) d[k][j]=min(d[k][j],d[k][j-1]+h[i][j-1]);
            for(j=c-2;j>=0;j--) d[k][j]=min(d[k][j],d[k][j+1]+h[i][j]);
            for(j=0;j<c;j++) d[k][j]+=v[i][j];
        }
        for(j=1;j<c;j++) d[k][j]=min(d[k][j],d[k][j-1]+h[i][j-1]);
        for(j=c-2;j>=0;j--) d[k][j]=min(d[k][j],d[k][j+1]+h[i][j]);
    }
}

void mgDynamic(Node *no,int mid){
    int i,j,k,t=0;
    int l[2][C+1];
    l[0][0]=0;
    l[0][1]=c-1;

    for(i=-(c-1);i<0;i++){
        l[!t][0]=0;
        for(j=-i;j<c;j++){
            int p;
            p=k=l[t][j+i];
            no->d[j][j+i]=no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k];
            for(k=l[t][j+i]+1;k<=l[t][j+i+1];k++){
                if(no->d[j][j+i]>no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k]){
                    p=k;
                    no->d[j][j+i]=no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k];
                }
            }
            l[!t][j+i+1]=p;
        }
        l[!t][i+c+1]=c-1;
        t=!t;
    }
    for(i=0;i<c;i++){
        for(j=0;j<c-i;j++){
            int p;
            p=k=l[t][j+i];
            no->d[j][j+i]=no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k];
            for(k=l[t][j+i]+1;k<=l[t][j+i+1];k++){
                if(no->d[j][j+i]>no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k]){
                    p=k;
                    no->d[j][j+i]=no->chi[0]->d[j][k]+no->chi[1]->d[k][j+i]+v[mid][k];
                }
            }
            l[!t][j+i+1]=p;
        }
        t=!t;
    }
}

void setTree(int s,int e,Node *no){
    if(s+8>=e){
        dp(no->d,s,e);
        return;
    }
    int mid=(s+e)/2;
    if(!no->chi[0]) no->chi[0]=new Node();
    if(!no->chi[1]) no->chi[1]=new Node();
    setTree(s,mid,no->chi[0]);
    setTree(mid+1,e,no->chi[1]);

    mgDynamic(no,mid);
}

void updateTree(int s,int e,int x,Node *no){
    if(e<x || x<s) return;
    if(s+8>=e){
        dp(no->d,s,e);
        return;
    }
    int mid=(s+e)/2;
    updateTree(s,mid,x,no->chi[0]);
    updateTree(mid+1,e,x,no->chi[1]);
    int i,j,k;

    mgDynamic(no,mid);
}

void init(int _r, int _c, int H[5000][200], int V[5000][200]) {
    int i,j;
    r=_r; c=_c;
    for(i=0;i<r;i++) for(j=0;j<c-1;j++) h[i][j]=H[i][j];
    for(i=0;i<r-1;i++) for(j=0;j<c;j++) v[i][j]=V[i][j];

    rt=new Node();
    setTree(0,r-1,rt);
}

void changeH(int P, int Q, int W) {
    h[P][Q]=W;
    updateTree(0,r-1,P,rt);
}

void changeV(int P, int Q, int W) {
    v[P][Q]=W;
    updateTree(0,r-1,P,rt);
}

int escape(int V1, int V2) {
    return rt->d[V1][V2];
}
# 결과 실행 시간 메모리 Grader output
1 Memory limit exceeded 31 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17000 KB Output is correct - 6 tokens
2 Correct 0 ms 17000 KB Output is correct - 6 tokens
3 Correct 0 ms 17000 KB Output is correct - 6 tokens
4 Correct 0 ms 17960 KB Output is correct - 405 tokens
5 Correct 2 ms 17960 KB Output is correct - 405 tokens
6 Correct 2 ms 17960 KB Output is correct - 405 tokens
7 Correct 0 ms 17960 KB Output is correct - 405 tokens
8 Correct 0 ms 17640 KB Output is correct - 366 tokens
9 Correct 0 ms 17640 KB Output is correct - 405 tokens
10 Correct 0 ms 17960 KB Output is correct - 366 tokens
11 Correct 86 ms 17960 KB Output is correct - 200005 tokens
12 Correct 0 ms 17960 KB Output is correct - 405 tokens
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 21800 KB Output is correct - 105 tokens
2 Correct 120 ms 21800 KB Output is correct - 105 tokens
3 Correct 135 ms 21800 KB Output is correct - 105 tokens
4 Correct 138 ms 21800 KB Output is correct - 105 tokens
5 Correct 133 ms 21800 KB Output is correct - 105 tokens
6 Correct 0 ms 17000 KB Output is correct - 6 tokens
7 Correct 0 ms 17000 KB Output is correct - 6 tokens
8 Correct 0 ms 17000 KB Output is correct - 6 tokens
9 Correct 537 ms 21800 KB Output is correct - 105 tokens
10 Correct 0 ms 17000 KB Output is correct - 8 tokens
# 결과 실행 시간 메모리 Grader output
1 Memory limit exceeded 0 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 21800 KB Output is correct - 105 tokens
2 Correct 122 ms 21800 KB Output is correct - 105 tokens
3 Correct 128 ms 21800 KB Output is correct - 105 tokens
4 Correct 137 ms 21800 KB Output is correct - 105 tokens
5 Correct 137 ms 21800 KB Output is correct - 105 tokens
6 Memory limit exceeded 29 ms 262144 KB Memory limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 21800 KB Output is correct - 105 tokens
2 Correct 119 ms 21800 KB Output is correct - 105 tokens
3 Correct 136 ms 21800 KB Output is correct - 105 tokens
4 Incorrect 135 ms 21800 KB Output isn't correct - wrong output format : File not found: "/var/www/temp/16753/outputUkr6_1"
5 Halted 0 ms 0 KB -
6 Memory limit exceeded 31 ms 262144 KB Memory limit exceeded
7 Halted 0 ms 0 KB -