답안 #4606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4606 2013-11-10T07:15:24 Z cki86201 웜뱃 (IOI13_wombats) C++
0 / 100
2272 ms 178748 KB
#include "wombats.h"
#include<stdlib.h>
#include<queue>
#include<vector>
#include<functional>
#include<string.h>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> P;
typedef pair<int,P> Pi;
const int id = 512;
const int inf = 1e9;

int H[5000][200],V[5000][200];
int T[1030][200][200];
int R,C;
bool check[5000][200];

void upd(int x,int y)
{
	int i,j;
	int A[200];
	memset(A,0,sizeof(A));
	for(i=x-1;i>=0;i--)A[i]=A[i+1]+H[10*y][i];
	for(i=x+1;i<R;i++)A[i]=A[i-1]+H[10*y][i-1];
	bool check[200];
	for(i=y+1;i<=y+10 && i<R;i++){
		priority_queue <P,vector<P>, greater<P> > pq;
		memset(check,0,sizeof(check));
		for(j=0;j<C;j++)pq.push(P(A[j]+V[i-1][j],j));
		int cnt = 0;
		while(!pq.empty() && cnt!=C){
			P t = pq.top();
			pq.pop();
			if(check[t.Y])continue;
			check[t.Y]=1;
			A[t.Y]=t.X;
			cnt++;
			if(t.Y+1<C && !check[t.Y+1])pq.push(P(t.X+H[i][t.Y],t.Y+1));
			if(t.Y!=0 && !check[t.Y-1])pq.push(P(t.X+H[i][t.Y-1],t.Y-1));
		}
	}
	for(i=0;i<C;i++)T[id+y][x][i]=A[i];
}

void Union(int t)
{
	if(t==256){
		t++;
		t--;
	}
	int i,j,k;
	int sk[200];
	for(i=0;i<C;i++)sk[i]=0;
	sk[0]=C-1;
	for(i=0;i<C;i++)for(j=0;j<C;j++)T[t][i][j]=inf;
	for(i=C-1;i>=-C+1;i--){
		for(j=min(C-1,C-i-1);j>=0&&j+i>=0;j--){
			int s=j==max(0,-i)?0:sk[j-1];
			int d=j==min(C-1,C-i-1)?C-1:sk[j];
			for(k=s;k<=d;k++){
				if(T[t][j][j+i] > T[t<<1][j][k] + T[t<<1|1][k][j+i]){
					T[t][j][j+i]=T[t<<1][j][k] + T[t<<1|1][k][j+i];
					sk[j]=k;
				}
			}
		}
	}
	for(i=0;i<C;i++)if(T[t][i][i]==inf)T[t][i][i]=0;
}

void init(int R, int C, int H_[5000][200], int V_[5000][200]){
	int i,j;
	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];
	::R=R;
	::C=C;
	for(i=0;i<C;i++){
		for(j=0;10*j<R;j++){
			upd(i,j);
		}
		for(;j<id;j++){
			for(int u=0;u<C;u++)T[id+j][i][u]=i==u?0:inf;
		}
	}
	for(i=id-1;i;i--)Union(i);
}



void changeH(int P, int Q, int W){
	H[P][Q]=W;
	int i,r=P/10;
	for(i=0;i<C;i++)upd(i,r);
	r+=id;
	r>>=1;
	while(r){
		Union(r);
		r>>=1;
	}
}

void changeV(int P, int Q, int W) {
    V[P][Q]=W;
    int i,r=P/10;
	for(i=0;i<C;i++)upd(i,r);
	r+=id;
	r>>=1;
	while(r){
		Union(r);
		r>>=1;
	}
}

int escape(int V1, int V2){
	return T[1][V1][V2];
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 178744 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 178748 KB Output is correct
2 Correct 0 ms 178748 KB Output is correct
3 Correct 0 ms 178748 KB Output is correct
4 Incorrect 8 ms 178748 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2260 ms 178748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 178744 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2236 ms 178748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2272 ms 178748 KB Output isn't correct
2 Halted 0 ms 0 KB -