Submission #19021

#TimeUsernameProblemLanguageResultExecution timeMemory
19021suhgyuho_william철로 (IOI14_rail)C++98
8 / 100
90 ms752 KiB
#include "rail.h"
#include <algorithm>

using namespace std;

int dis0[5010];
int disx[5010];
int bef[5010];
int op[5010],num[5010];
bool cmp(int x,int y){
	return dis0[x] < dis0[y];
}

void findLocation(int N, int first, int location[], int stype[]){
	int i,j;
	int small,x;
	int t,v,nv;
	int rear,tmp;

	location[0] = first; stype[0] = 1;
	small = 999999999;
    for(i=1; i<N; i++){
		dis0[i] = getDistance(0,i);
		if(small > dis0[i]){
			small = dis0[i];
			x = i;
		}
    }
    location[x] = first+dis0[x];
    stype[x] = 2;
	for(i=1; i<N; i++){
		if(i == x) continue;
		disx[i] = getDistance(x,i);
		if(dis0[i] == dis0[x]+disx[i]) op[i] = 2;
		else op[i] = 1;
	}
	rear = 0;
	for(i=1; i<N; i++){
		if(op[i] == 1){
			rear++;
			num[rear] = i;
		}
	}
	sort(num+1,num+rear+1,cmp);
	tmp = 0; bef[0] = -999999999;
	for(i=1; i<=rear; i++){
		v = num[i];
		t = getDistance(v,0);
		if(dis0[v] == t){
			location[v] = first+dis0[v];
			stype[v] = 2;
			bef[v] = tmp;
			tmp = v;
		}else{
			for(j=1; j<i; j++){
				nv = num[j];
				if(stype[nv] == 1) continue;
				location[v] = location[nv]-(t-dis0[nv]);
				if(location[bef[nv]] < location[v] && location[v] < location[nv]) break;
			}
			stype[v] = 1;
		}
	}
	rear = 0;
	for(i=1; i<N; i++){
		if(op[i] == 2){
			rear++;
			num[rear] = i;
		}
	}

}

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:29:31: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     location[x] = first+dis0[x];
                         ~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...