답안 #4591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4591 2013-11-07T10:06:51 Z cki86201 웜뱃 (IOI13_wombats) C++
55 / 100
20000 ms 18100 KB
#include "wombats.h"
#include<stdlib.h>
#include<queue>
#include<vector>
#include<functional>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> P;
typedef pair<int,P> Pi;

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

//55point;

void build2()
{
	int i;
	T2[0][0][0]=0,T2[0][0][1]=H[0][0];
	for(i=1;i<R;i++){
		if(T2[0][i-1][0]+V[i-1][0]>T2[0][i-1][1]+V[i-1][1]){
			T2[0][i][1]=T2[0][i-1][1]+V[i-1][1];
			T2[0][i][0]=min(T2[0][i][1]+H[i][0],T2[0][i-1][0]+V[i-1][0]);
		}
		else{
			T2[0][i][0]=T2[0][i-1][0]+V[i-1][0];
			T2[0][i][1]=min(T2[0][i][0]+H[i][0],T2[0][i-1][1]+V[i-1][1]);
		}
	}
	T2[1][0][1]=0,T2[1][0][0]=H[0][0];
	for(i=1;i<R;i++){
		if(T2[1][i-1][0]+V[i-1][0]>T2[1][i-1][1]+V[i-1][1]){
			T2[1][i][1]=T2[1][i-1][1]+V[i-1][1];
			T2[1][i][0]=min(T2[1][i][1]+H[i][0],T2[1][i-1][0]+V[i-1][0]);
		}
		else{
			T2[1][i][0]=T2[1][i-1][0]+V[i-1][0];
			T2[1][i][1]=min(T2[1][i][0]+H[i][0],T2[1][i-1][1]+V[i-1][1]);
		}
	}
}

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;
	if(C==1)for(i=1;i<R;i++)T[i]=T[i-1]+V[i-1][0];
	if(C==2)build2();
}

void changeH(int P, int Q, int W){
	H[P][Q]=W;
	if(C==2)build2();
}

void changeV(int P, int Q, int W) {
    V[P][Q]=W;
    if(C==1)for(int i=P+1;i<R;i++)T[i]=T[i-1]+V[i-1][0];
    if(C==2)build2();
}

int escape(int V1, int V2) {
	if(C==1)return T[R-1];
	if(C==2)return T2[V1][R-1][V2];
	priority_queue <Pi,vector<Pi>,greater<Pi> > pq;
	int i,j;
	for(i=0;i<R;i++)for(j=0;j<C;j++)check[i][j]=0;
	pq.push(Pi(0,P(0,V1)));
	while(!pq.empty()){
		Pi t=pq.top();
		pq.pop();
		if(check[t.Y.X][t.Y.Y])continue;
		check[t.Y.X][t.Y.Y]=1;
		if(t.Y.X == R-1 && t.Y.Y == V2)return t.X;
		if(t.Y.Y!=C-1 && !check[t.Y.X][t.Y.Y+1])pq.push(Pi(t.X+H[t.Y.X][t.Y.Y],P(t.Y.X,t.Y.Y+1)));
		if(t.Y.Y && !check[t.Y.X][t.Y.Y-1])pq.push(Pi(t.X+H[t.Y.X][t.Y.Y-1],P(t.Y.X,t.Y.Y-1)));
		if(t.Y.X!=R-1 && !check[t.Y.X+1][t.Y.Y])pq.push(Pi(t.X+V[t.Y.X][t.Y.Y],P(t.Y.X+1,t.Y.Y)));
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 17908 KB Output is correct
2 Correct 0 ms 17908 KB Output is correct
3 Correct 96 ms 17908 KB Output is correct
4 Correct 8 ms 17908 KB Output is correct
5 Correct 16 ms 17908 KB Output is correct
6 Correct 0 ms 17908 KB Output is correct
7 Correct 0 ms 17908 KB Output is correct
8 Correct 0 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17908 KB Output is correct
2 Correct 0 ms 17908 KB Output is correct
3 Correct 0 ms 17908 KB Output is correct
4 Correct 28 ms 17908 KB Output is correct
5 Correct 20 ms 17908 KB Output is correct
6 Correct 24 ms 17908 KB Output is correct
7 Correct 20 ms 17908 KB Output is correct
8 Correct 20 ms 17908 KB Output is correct
9 Correct 24 ms 17908 KB Output is correct
10 Correct 20 ms 17908 KB Output is correct
11 Correct 11904 ms 17908 KB Output is correct
12 Correct 24 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 17908 KB Output is correct
2 Correct 152 ms 18100 KB Output is correct
3 Correct 208 ms 17908 KB Output is correct
4 Correct 204 ms 17908 KB Output is correct
5 Correct 204 ms 17908 KB Output is correct
6 Correct 0 ms 17908 KB Output is correct
7 Correct 0 ms 17908 KB Output is correct
8 Correct 0 ms 17908 KB Output is correct
9 Correct 240 ms 17908 KB Output is correct
10 Correct 0 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 17908 KB Output is correct
2 Correct 52 ms 17908 KB Output is correct
3 Correct 68 ms 17908 KB Output is correct
4 Correct 108 ms 17908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 17908 KB Output is correct
2 Correct 160 ms 18100 KB Output is correct
3 Correct 208 ms 17908 KB Output is correct
4 Correct 212 ms 17908 KB Output is correct
5 Correct 208 ms 17908 KB Output is correct
6 Correct 64 ms 17908 KB Output is correct
7 Correct 56 ms 17908 KB Output is correct
8 Correct 68 ms 17908 KB Output is correct
9 Correct 116 ms 17908 KB Output is correct
10 Correct 12 ms 17908 KB Output is correct
11 Correct 0 ms 17908 KB Output is correct
12 Correct 92 ms 17908 KB Output is correct
13 Correct 4 ms 17908 KB Output is correct
14 Correct 12 ms 17908 KB Output is correct
15 Correct 0 ms 17908 KB Output is correct
16 Correct 0 ms 17908 KB Output is correct
17 Correct 0 ms 17908 KB Output is correct
18 Correct 28 ms 17908 KB Output is correct
19 Correct 20 ms 17908 KB Output is correct
20 Correct 24 ms 17908 KB Output is correct
21 Correct 16 ms 17908 KB Output is correct
22 Correct 20 ms 17908 KB Output is correct
23 Correct 24 ms 17908 KB Output is correct
24 Correct 20 ms 17908 KB Output is correct
25 Correct 11920 ms 17908 KB Output is correct
26 Correct 24 ms 17908 KB Output is correct
27 Correct 244 ms 17908 KB Output is correct
28 Execution timed out 20000 ms 17908 KB Program timed out
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 17908 KB Output is correct
2 Correct 160 ms 18100 KB Output is correct
3 Correct 212 ms 17908 KB Output is correct
4 Correct 212 ms 17908 KB Output is correct
5 Correct 208 ms 17908 KB Output is correct
6 Correct 68 ms 17908 KB Output is correct
7 Correct 56 ms 17908 KB Output is correct
8 Correct 68 ms 17908 KB Output is correct
9 Correct 100 ms 17908 KB Output is correct
10 Correct 8 ms 17908 KB Output is correct
11 Correct 0 ms 17908 KB Output is correct
12 Correct 96 ms 17908 KB Output is correct
13 Correct 8 ms 17908 KB Output is correct
14 Correct 12 ms 17908 KB Output is correct
15 Correct 1632 ms 17908 KB Output is correct
16 Execution timed out 20000 ms 17908 KB Program timed out
17 Halted 0 ms 0 KB -