답안 #617783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617783 2022-08-01T14:12:03 Z amunduzbaev 분수 공원 (IOI21_parks) C++17
5 / 100
298 ms 20816 KB
#include "parks.h"

#include "bits/stdc++.h"
using namespace std;

#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
typedef long long ll;

int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	
	map<ar<int, 2>, int> mm;
	for(int i=0;i<n;i++){
		swap(x[i], y[i]);
		mm[{x[i], y[i]}] = i;
	}
	
	vector<ar<int, 2>> e, p;
	vector<int> par(n), sz(n, 1);
	iota(par.begin(), par.end(), 0);
	function<int(int)> f = [&](int x) { return (par[x] == x ? x : par[x] = f(par[x])); };
	auto merge = [&](int a, int b){
		a = f(a), b = f(b);
		if(a == b) return false;
		if(sz[a] < sz[b]) swap(a, b);
		par[b] = a, sz[a] += sz[b];
		return true;
	};
	
	for(int i=0;i<n;i++){
		if(mm.count({x[i], y[i] - 2})){
			int j = mm[{x[i], y[i] - 2}];
			if(merge(i, j)){
				e.push_back({j, i});
				p.push_back({-1, -1});
			}
		}
	}
	
	for(int i=0;i<n;i++){
		if(y[i] == 2 || y[i] == 6){
			if(mm.count({x[i] - 2, y[i]})){
				int j = mm[{x[i] - 2, y[i]}];
				if(merge(i, j)){
					e.push_back({j, i});
					p.push_back({x[i] - 1, y[i] + (x[i] == 2 ? -1 : +1)});
				}
			}
		}
	}
	
	for(int i=0;i<n;i++){
		if(y[i] == 4){
			if(mm.count({x[i] - 2, y[i]})){
				int j = mm[{x[i] - 2, y[i]}];
				if(merge(i, j)){
					e.push_back({j, i});
					p.push_back({-1, -1});
				}
			}
		}
	}
	
	if(sz[f(0)] != n) return 0;
	assert((int)e.size() == n - 1);
	par.pop_back();
	iota(par.begin(), par.end(), 0);
	sort(par.begin(), par.end(), [&](int i, int j){
		if(x[e[i][0]] != x[e[j][0]]){
			return x[e[i][0]] < x[e[j][0]];
		} else {
			int a = (x[e[i][0]] != x[e[i][1]]), b = (x[e[j][0]] != x[e[j][1]]);
			return a < b;
		}
	});
	
	mm.clear();
	for(auto i : par){
		if(~p[i][0]) continue;
		//~ cout<<e[i][0]<<" "<<e[i][1]<<"\n";
		if(x[e[i][0]] == x[e[i][1]]){
			int Y = (y[e[i][0]] + y[e[i][1]]) / 2;
			p[i] = {x[e[i][0]] - 1, Y};
			if(mm.count(p[i])){
				p[i][0] += 2;
				assert(!mm.count(p[i]));
			}
			mm[p[i]] = 1;
		} else {
			int X = (x[e[i][0]] + x[e[i][1]]) / 2;
			p[i] = {X, y[e[i][0]] + 1};
			if(mm.count(p[i])){
				p[i][1] -= 2;
				assert(!mm.count(p[i]));
			}
			
			mm[p[i]] = 1;
		}
	}
	
	mm.clear();
	vector<int> u(n - 1), v(n - 1), A(n - 1), B(n - 1);
	for(int i=0;i+1<n;i++){
		u[i] = e[i][0], v[i] = e[i][1], A[i] = p[i][0], B[i] = p[i][1];
		swap(A[i], B[i]);
		assert(!mm.count(p[i]));
		mm[p[i]];
	}
	
	build(u, v, A, B);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
17 Incorrect 0 ms 212 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
17 Incorrect 298 ms 20816 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 225 ms 15068 KB Output is correct
10 Correct 11 ms 1896 KB Output is correct
11 Correct 71 ms 8232 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 30 ms 5076 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 224 ms 15172 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -