Submission #128546

#TimeUsernameProblemLanguageResultExecution timeMemory
128546antimirageRail (IOI14_rail)C++14
Compilation error
0 ms0 KiB
#include "rail.h"
#include "grader.cpp"
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 5005; 

int dist[2][N];

vector <int> lft, rght;

bool cmp1 (int a, int b) {
	return dist[0][a] < dist[0][b];
}
bool cmp2 (int a, int b) {
	return dist[1][a] < dist[1][b];
}

void findLocation(int n, int pos, int a[], int t[])
{
	int mn = 1e9 + 7, ind;
	a[0] = pos, t[0] = 1;
	
	for (int i = 1; i < n; i++) {	
		dist[0][i] = getDistance(0, i);
		if (dist[0][i] < mn) {
			mn = dist[0][i];
			ind = i;
		}
	}
	assert(mn != 0);
	
	a[ind] = pos + mn; t[ind] = 2;
	
	for (int i = 1; i < n; i++) {
		if (i == ind) continue;
		
		dist[1][i] = getDistance(ind, i);
		
		if (dist[0][i] < dist[1][i]) {
			rght.pb(i);
		}
		else if (dist[0][i] > dist[1][i]) {
			lft.pb(i);
		}
		else
			assert(0);
	}
	sort(all(rght), cmp1);
	sort(all(lft), cmp2);
	
	int lastd = -1, lastc = 0;
	
	for (int i = 0; i < (int)rght.size(); i++) {
		int it = rght[i];
		
		if (lastd == -1) {
			lastd = it;
			a[it] = pos + dist[0][it];
			t[it] = 2;
		}
		else {
			int res = getDistance(lastd, it), nxt = a[0] + dist[0][it];
			
			int ok = a[lastd] - res;
			
			for (int j = 0; j < i; j++) {
				if (t[rght[j]] == 2 && a[rght[j]] > ok && a[rght[j]] - ok + dist[0][j] == dist[0][it] )
					assert(0);
			}
			if (res == 2 * (a[lastd] - a[lastc]) + nxt - a[lastd]) {
				a[it] = nxt, lastd = it; t[it] = 2;
			}
			else {
				a[it] = a[lastd] - res; t[it] = 1;
				if (a[lastc] < a[it])
					lastc = it;
			}
		}
	}
	lastc = -1, lastd = ind;
	pos = a[ind];
	
	for (int i = 0; i < (int)lft.size(); i++) {
		int it = lft[i];
		
		if (lastc == -1) {
			lastc = it;
			a[it] = pos - dist[1][it];
			t[it] = 1;
		}
		else {
			int res = getDistance(lastc, it), nxt = a[ind] - dist[1][it];
			
			assert(res != 0);
			
			int ok = a[lastc] + res;
			
			for (int j = 0; j < i; j++) {
				if (t[lft[j]] == 1 && a[lft[j]] < ok &&  ok - a[lft[j]] + dist[1][j] == dist[1][it] )
					assert(0);
			}
			
			if (res == 2 * (a[lastd] - a[lastc]) +  a[lastc] - nxt) {
				a[it] = nxt, lastc = it; t[it] = 1;
			}
			else {
				a[it] = a[lastc] + res; t[it] = 2;
				if (a[lastd] > a[it])
					lastd = it;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		assert(a[i] >= -1);
	}
}

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:40:7: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
  a[ind] = pos + mn; t[ind] = 2;
       ^
/tmp/ccjOb2Oy.o: In function `getDistance':
grader.cpp:(.text+0x0): multiple definition of `getDistance'
/tmp/ccczCaKd.o:rail.cpp:(.text+0x40): first defined here
/tmp/ccjOb2Oy.o:(.bss+0x0): multiple definition of `cnt'
/tmp/ccczCaKd.o:(.bss+0x9ca8): first defined here
/tmp/ccjOb2Oy.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccczCaKd.o:rail.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status