답안 #814397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
814397 2023-08-08T07:15:43 Z becaido 분수 공원 (IOI21_parks) C++17
45 / 100
666 ms 38420 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "parks.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#ifdef WAIMAI
void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);
#endif

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int SIZE = 2e5 + 5;

vector<int> adj[SIZE];
map<pair<int, int>, int> mp;
int deg[SIZE], pa[SIZE];
queue<int> q;

int construct_roads(vector<int> x, vector<int> y) {
    int n = x.size();
    FOR (i, 0, n - 1) mp[{x[i], y[i]}] = i;
    FOR (i, 0, n - 1) FOR (j, 0, 3) {
        int tx = x[i] + 2 * dx[j];
        int ty = y[i] + 2 * dy[j];
        if (mp.count({tx, ty})) adj[i].pb(mp[{tx, ty}]);
    }
    q.push(0);
    fill(pa, pa + n, -1);
    while (q.size()) {
        int pos = q.front();
        q.pop();
        for (int np : adj[pos]) if (np != 0 && pa[np] == -1) {
            pa[np] = pos;
            deg[pos]++;
            q.push(np);
        }
    }
    FOR (i, 1, n - 1) if (pa[i] == -1) return 0;
    FOR (i, 0, n - 1) if (!deg[i]) q.push(i);
    vector<int> u, v, a, b;
    set<pair<int, int>> s;
    while (q.size()) {
        int pos = q.front();
        q.pop();
        if (pos == 0) break;
        int lx, ly, rx, ry;
        tie(lx, ly) = make_pair(x[pos], y[pos]);
        tie(rx, ry) = make_pair(x[pa[pos]], y[pa[pos]]);
        u.pb(pos), v.pb(pa[pos]);
        int mx = (lx + rx) / 2, my = (ly + ry) / 2;
        if (lx == rx) {
            int y = min(ly, ry);
            if ((lx + y) % 4) a.pb(lx + 1), b.pb(my);
            else a.pb(lx - 1), b.pb(my);
        } else {
            int x = min(lx, rx);
            if ((x + ly) % 4) a.pb(mx), b.pb(ly - 1);
            else a.pb(mx), b.pb(ly + 1);
        }
        if (u.size() > a.size()) assert(0);
        if (--deg[pa[pos]] == 0) q.push(pa[pos]);
    }
    build(u, v, a, b);
    return 1;
}

/*
in1
5
4 4
4 6
6 4
4 2
2 4
out1
1
4
0 2 5 5
0 1 3 5
3 0 5 3
4 0 3 3

in2
2
2 2
4 6
out2
0
*/

#ifdef WAIMAI
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;
}

int main() {
	assert(scanf("%d", &n) == 1);
	vector<int> x(n), y(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(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;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 4 ms 4964 KB Output is correct
20 Correct 639 ms 38396 KB Output is correct
21 Correct 502 ms 38336 KB Output is correct
22 Correct 533 ms 38420 KB Output is correct
23 Correct 374 ms 33396 KB Output is correct
24 Correct 268 ms 21804 KB Output is correct
25 Correct 467 ms 28688 KB Output is correct
26 Correct 383 ms 28728 KB Output is correct
27 Correct 541 ms 37924 KB Output is correct
28 Correct 575 ms 37988 KB Output is correct
29 Correct 596 ms 38040 KB Output is correct
30 Correct 666 ms 37928 KB Output is correct
31 Correct 4 ms 4948 KB Output is correct
32 Correct 24 ms 7700 KB Output is correct
33 Correct 112 ms 13200 KB Output is correct
34 Correct 451 ms 38028 KB Output is correct
35 Correct 13 ms 6116 KB Output is correct
36 Correct 72 ms 10812 KB Output is correct
37 Correct 173 ms 16724 KB Output is correct
38 Correct 174 ms 18376 KB Output is correct
39 Correct 309 ms 23312 KB Output is correct
40 Correct 364 ms 28412 KB Output is correct
41 Correct 491 ms 33244 KB Output is correct
42 Correct 572 ms 38256 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 4948 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 4 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 4 ms 5204 KB Output is correct
55 Correct 5 ms 5332 KB Output is correct
56 Correct 167 ms 21560 KB Output is correct
57 Correct 278 ms 29108 KB Output is correct
58 Correct 278 ms 29112 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 3 ms 4948 KB Output is correct
62 Correct 414 ms 38040 KB Output is correct
63 Correct 443 ms 38008 KB Output is correct
64 Correct 408 ms 37888 KB Output is correct
65 Correct 8 ms 5460 KB Output is correct
66 Correct 12 ms 5828 KB Output is correct
67 Correct 215 ms 21616 KB Output is correct
68 Correct 305 ms 29844 KB Output is correct
69 Correct 431 ms 38136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
17 Correct 450 ms 37952 KB Output is correct
18 Correct 402 ms 38040 KB Output is correct
19 Correct 441 ms 38020 KB Output is correct
20 Correct 572 ms 37584 KB Output is correct
21 Correct 498 ms 34012 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 73 ms 10488 KB Output is correct
24 Correct 28 ms 7252 KB Output is correct
25 Correct 105 ms 13108 KB Output is correct
26 Correct 237 ms 19036 KB Output is correct
27 Correct 217 ms 21572 KB Output is correct
28 Correct 305 ms 25832 KB Output is correct
29 Correct 378 ms 29932 KB Output is correct
30 Correct 434 ms 34012 KB Output is correct
31 Correct 569 ms 38248 KB Output is correct
32 Correct 543 ms 38192 KB Output is correct
33 Correct 470 ms 37964 KB Output is correct
34 Correct 9 ms 5588 KB Output is correct
35 Correct 12 ms 5996 KB Output is correct
36 Correct 186 ms 21640 KB Output is correct
37 Correct 420 ms 29868 KB Output is correct
38 Correct 406 ms 38192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 168 ms 21564 KB Output is correct
10 Correct 12 ms 6868 KB Output is correct
11 Correct 61 ms 14008 KB Output is correct
12 Correct 21 ms 7648 KB Output is correct
13 Correct 36 ms 10060 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 4 ms 5204 KB Output is correct
16 Correct 149 ms 21520 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
19 Halted 0 ms 0 KB -