답안 #740222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740222 2023-05-12T07:33:16 Z vjudge1 분수 공원 (IOI21_parks) C++17
컴파일 오류
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;
}

#include "parks.h"
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int maxn = 2e5 + 100;
int ord[maxn];
int used[maxn];
int sum;
vector<int>g[maxn];

void dfs(int v){
	used[v] = 1;
	sum++;
	for(auto to: g[v]){
		if(!used[to]) dfs(to);
	}
}

int construct_roads(std::vector<int> x, std::vector<int> y){
    int n = x.size();
	if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }
	vector<pair<int, int>>c[2];
	for(int i=0; i<n; i++){
		int num = 0;
		if(x[i] == 4) num = 1; 
    	c[num].push_back({y[i], i});
	}
	sort(c[0].begin(), c[0].end());
	sort(c[1].begin(), c[1].end());
	bool ok = 1;
	vector<int>u, v, a, b;
	if(c[1].size() == 0){
		for(int i=1; i<n; i++){
			if(c[0][i].first-c[0][i-1].first != 2) ok = 0;
			u.push_back(c[0][i-1].second);
			v.push_back(c[0][i].second);
			a.push_back(1);
			b.push_back(c[0][i].first-1);
		}
	} else{
		for(int i=1; i<c[0].size(); i++){
			u.push_back(c[0][i-1].second);
			v.push_back(c[0][i].second);
			a.push_back(1);
			b.push_back(c[0][i].first-1);
			g[c[0][i].s].push_back(c[0][i-1].s);
			g[c[0][i-1].s].push_back(c[0][i].s);
		}
		for(int i=1; i<c[1].size(); i++){
			u.push_back(c[1][i-1].second);
			v.push_back(c[1][i].second);
			a.push_back(5);
			b.push_back(c[1][i].first-1);
			g[c[1][i].s].push_back(c[1][i-1].s);
			g[c[1][i-1].s].push_back(c[1][i].s);
		}
		int pos = 0;
		for(int i=0; i<c[0].size(); i++){
			while(pos < c[1].size() && c[1][pos].f < c[0][i].f) pos++;
			if(pos < c[1].size() && c[1][pos].f == c[0][i].f){
				u.push_back(c[0][i].s);
				v.push_back(c[1][pos].s);
				a.push_back(3);
				b.push_back(c[0][i].f-1);
				g[c[0][i].s].push_back(c[1][pos].s);
				g[c[1][pos].s].push_back(c[0][i].s);
			}
		}
		dfs(0);
		if(sum < n) ok = 0;
	}
	if(ok) build(u, v, a, b);
    return ok;
}


int main() {
	assert(scanf("%d", &n) == 1);
	vector<int>x, y;
	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(x, y);

	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

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i=1; i<c[0].size(); i++){
      |                ~^~~~~~~~~~~~
parks.cpp:84:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for(int i=1; i<c[1].size(); i++){
      |                ~^~~~~~~~~~~~
parks.cpp:93:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for(int i=0; i<c[0].size(); i++){
      |                ~^~~~~~~~~~~~
parks.cpp:94:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |    while(pos < c[1].size() && c[1][pos].f < c[0][i].f) pos++;
      |          ~~~~^~~~~~~~~~~~~
parks.cpp:95:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |    if(pos < c[1].size() && c[1][pos].f == c[0][i].f){
      |       ~~~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccB4WQWb.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/ccT8lIm9.o:parks.cpp:(.text+0x680): first defined here
/usr/bin/ld: /tmp/ccB4WQWb.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccT8lIm9.o:parks.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status