Submission #740073

# Submission time Handle Problem Language Result Execution time Memory
740073 2023-05-12T05:15:47 Z vjudge1 Fountain Parks (IOI21_parks) C++17
Compilation error
0 ms 0 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;


static void check(bool cond, string message) {
	if (!cond) {
		printf("%s\n", message.c_str());
		fclose(stdout);
		exit(0);
	}
}

static int n;
static bool build_called;
static int m;
static vector<int> _u, _v, _a, _b;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
	check(!build_called, "build is called more than once");
	build_called = true;
	m = u.size();
	check(int(v.size()) == m, "u.size() != v.size()");
	check(int(a.size()) == m, "u.size() != a.size()");
	check(int(b.size()) == m, "u.size() != b.size()");
	_u = u;
	_v = v;
	_a = a;
	_b = b;
}

const int maxn = 2e5 + 100;
int ord[maxn];
vector<int>x, y;

int construct_roads() {
    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }
    for(int i=0; i<n; i++){
    	ord[i] = i;
	}
	sort(ord, ord+n, [](int a, int b){
		return y[a] < y[b];
	});
	bool ok = 1;
	vector<int>u, v, a, b;
	for(int i=1; i<n; i++){
		if(y[i]-y[i-1] != 2) ok = 0;
		u.push_back(ord[i-1]);
		v.push_back(ord[i]);
		a.push_back(1);
		b.push_back(y[ord[i]]-1);
	}
	if(ok) build(u, v, a, b);
    return ok;
}

int main() {
	assert(scanf("%d", &n) == 1);
	x.resize(n);
	y.resize(n);
	for (int i = 0; i < n; i++) {
		assert(scanf("%d%d", &x[i], &y[i]) == 2);
	}
	fclose(stdin);

	build_called = false;
	const int possible = construct_roads();

	check(possible == 0 || possible == 1, "Invalid return value of construct_roads()");
	if (possible == 1) {
		check(build_called, "construct_roads() returned 1 without calling build()");
	} else {
		check(!build_called, "construct_roads() called build() but returned 0");
	}
	
	printf("%d\n", possible);
	if (possible == 1) {
		printf("%d\n", m);
		for (int j = 0; j < m; j++) {
			printf("%d %d %d %d\n", _u[j], _v[j], _a[j], _b[j]);
		}
	}
	fclose(stdout);
	return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccnhEv6t.o: in function `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x270): multiple definition of `build(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccxkJn9t.o:parks.cpp:(.text+0x580): first defined here
/usr/bin/ld: /tmp/ccnhEv6t.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccxkJn9t.o:parks.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccnhEv6t.o: in function `main':
grader.cpp:(.text.startup+0x23c): undefined reference to `construct_roads(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status