답안 #620995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620995 2022-08-03T10:56:32 Z MKopchev 분수 공원 (IOI21_parks) C++17
15 / 100
751 ms 46596 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e5+42;

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);

map< pair<int,int>, int > seen;

int ask(int x,int y)
{
    if(seen.count({x,y}))return seen[{x,y}];

    return -1;
}

int parent[nmax];

int root(int node)
{
    if(node==parent[node])return node;

    parent[node]=root(parent[node]);

    return parent[node];
}

set< pair<int,int> > benches;

int construct_roads(std::vector<int> x, std::vector<int> y) {

    int n=x.size();

    if (n == 1) {
	build({}, {}, {}, {});
        return 1;
    }

    for(int i=0;i<x.size();i++)
        seen[{x[i],y[i]}]=i;

    for(int i=0;i<n;i++)
        parent[i]=i;

    vector<int> u={},v={},a={},b={};

    for(int i=0;i<n;i++)
    {
        int pos=ask(x[i]+2,y[i]);

        if(pos!=-1)
        {
            parent[root(pos)]=root(i);

            u.push_back(i);
            v.push_back(pos);

            pair<int,int> bench={x[i]+1,y[i]+1};

            if(benches.count(bench))bench.second-=2;

            a.push_back(bench.first);
            b.push_back(bench.second);

            benches.insert(bench);
        }

        pos=ask(x[i],y[i]+2);

        if(pos!=-1)
        {
            parent[root(pos)]=root(i);

            u.push_back(i);
            v.push_back(pos);

            pair<int,int> bench={x[i]+1,y[i]+1};

            if(benches.count(bench))bench.first-=2;

            a.push_back(bench.first);
            b.push_back(bench.second);

            benches.insert(bench);
        }
    }

    for(int i=0;i<n;i++)
        if(root(i)!=root(0))return 0;

    build(u,v,a,b);

    return 1;
}

/*
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;
}
*/

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<x.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 714 ms 46596 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 964 KB Output is correct
28 Correct 226 ms 18800 KB Output is correct
29 Correct 360 ms 28008 KB Output is correct
30 Correct 587 ms 37396 KB Output is correct
31 Correct 751 ms 46588 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 0 ms 320 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 312 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 231 ms 18780 KB Output is correct
46 Correct 418 ms 27020 KB Output is correct
47 Correct 415 ms 26968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 714 ms 46596 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 964 KB Output is correct
28 Correct 226 ms 18800 KB Output is correct
29 Correct 360 ms 28008 KB Output is correct
30 Correct 587 ms 37396 KB Output is correct
31 Correct 751 ms 46588 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 0 ms 320 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 312 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 231 ms 18780 KB Output is correct
46 Correct 418 ms 27020 KB Output is correct
47 Correct 415 ms 26968 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Incorrect 0 ms 212 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 5
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 561 ms 38036 KB Output is correct
21 Correct 627 ms 37980 KB Output is correct
22 Correct 599 ms 37876 KB Output is correct
23 Correct 409 ms 32036 KB Output is correct
24 Correct 297 ms 18356 KB Output is correct
25 Correct 562 ms 30816 KB Output is correct
26 Correct 571 ms 30852 KB Output is correct
27 Incorrect 648 ms 37164 KB Tree @(49, 3) appears more than once: for edges on positions 2560 and 2692
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
17 Correct 569 ms 37520 KB Output is correct
18 Incorrect 581 ms 37780 KB Tree @(50001, 50003) appears more than once: for edges on positions 11866 and 183491
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 201 ms 18652 KB Output is correct
10 Correct 11 ms 2260 KB Output is correct
11 Correct 66 ms 10136 KB Output is correct
12 Correct 21 ms 3372 KB Output is correct
13 Correct 45 ms 7064 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 191 ms 18708 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 714 ms 46596 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 5 ms 852 KB Output is correct
27 Correct 5 ms 964 KB Output is correct
28 Correct 226 ms 18800 KB Output is correct
29 Correct 360 ms 28008 KB Output is correct
30 Correct 587 ms 37396 KB Output is correct
31 Correct 751 ms 46588 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 0 ms 320 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 312 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 231 ms 18780 KB Output is correct
46 Correct 418 ms 27020 KB Output is correct
47 Correct 415 ms 26968 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Incorrect 0 ms 212 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 5
51 Halted 0 ms 0 KB -