답안 #815316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815316 2023-08-08T14:08:55 Z I_Love_EliskaM_ 분수 공원 (IOI21_parks) C++17
5 / 100
1072 ms 30236 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second

struct DSU {
	vector<int> p,sz;
	int tot;
	DSU(int n) {
		forn(i,n) p.pb(i), sz.pb(1);
		tot=n;
	}
	int get(int u) {
		return p[u]==u?u:get(p[u]);
	}
	void uni(int u, int v) {
		u=get(u), v=get(v);
		if (sz[u]<sz[v]) swap(u,v);
		sz[u]+=sz[v];
		p[v]=u;
		--tot;
	}
};

int p3(vector<int> x, vector<int> y) {

	int n=x.size();
	vector<int> u,v,a,b;
	map<pi,int> m;
	forn(i,n) m[{x[i],y[i]}]=i;
	DSU dsu(n);

	vector<pi> z1={{0,-2},{0,2}};
	vector<pi> z2={{-2,0},{2,0}};
	forn(i,n) {
		int f=x[i], s=y[i];
		for(auto&x:z1) {
			if (m.count({f+x.f,s+x.s})) {
				if (i<m[{f+x.f,s+x.s}]) {
					if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
					dsu.uni(i,m[{f+x.f,s+x.s}]);
					u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
				}
			}
		}
	}
	forn(i,n) {
		int f=x[i], s=y[i];
		for(auto&x:z2) {
			if (m.count({f+x.f,s+x.s})) {
				if (i<m[{f+x.f,s+x.s}]) {
					if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
					dsu.uni(i,m[{f+x.f,s+x.s}]);
					u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
				}
			}
		}
	}
	if (u.size()!=n-1) return 0;

	forn(i,n-1) {
		int x1=x[u[i]], y1=y[u[i]];
		int x2=x[v[i]], y2=y[v[i]];
		if (x1==x2) {
			if (x1==2) {
				a.pb(1);
				b.pb(max(y1,y2)-1);
			} else if (x1==6) {
				a.pb(7);
				b.pb(max(y1,y2)-1);
			} else {
				if (max(y1,y2)%4) {
					a.pb(3);
					b.pb(max(y1,y2)-1);
				} else {
					a.pb(5);
					b.pb(max(y1,y2)-1);
				}
			}
		} else {
			if ((max(x1,x2)+y1+2)%4) {
				a.pb(5);
				b.pb(y1+1);
			} else {
				a.pb(3);
				b.pb(y1-1);
			}
		}
	}
	build(u,v,a,b);
	return 1;
}

int construct_roads(vector<int> x, vector<int> y) {
	int mx=0; for(auto&v:x) mx=max(mx,v);
	if (mx<=6) return p3(x,y);

	int n=x.size();
	vector<int> u,v,a,b;
	map<pi,int> m;
	forn(i,n) m[{x[i],y[i]}]=i;
	DSU dsu(n);

	vector<pi> z={{-2,0},{2,0},{0,-2},{0,2}};
	forn(i,n) {
		int f=x[i], s=y[i];
		for(auto&x:z) {
			if (m.count({f+x.f,s+x.s})) {
				if (i<m[{f+x.f,s+x.s}]) {
					if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
					dsu.uni(i,m[{f+x.f,s+x.s}]);
					u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
				}
			}
		}
	}
	if (u.size()!=n-1) return 0;
	
	forn(i,n-1) {
		int x1=x[u[i]], y1=y[u[i]];
		int x2=x[v[i]], y2=y[v[i]];
		if (x1==x2) {
			if ((max(y1,y2)+x1)%4) {
				a.pb(x1+1);
				b.pb(max(y1,y2)-1);
			} else {
				a.pb(x1-1);
				b.pb(max(y1,y2)-1);
			}
		} else {
			if ((max(x1,x2)+y1)%4) {
				a.pb(max(x1,x2)-1);
				b.pb(y1-1);
			} else {
				a.pb(max(x1,x2)-1);
				b.pb(y1+1);
			}
		}
	}
	build(u,v,a,b);
	return 1;
}

Compilation message

parks.cpp: In function 'int p3(std::vector<int>, std::vector<int>)':
parks.cpp:64:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |  if (u.size()!=n-1) return 0;
      |      ~~~~~~~~^~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:122:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |  if (u.size()!=n-1) return 0;
      |      ~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[2], b[2]) = (5, 5) is not adjacent to edge between u[2]=0 @(4, 4) and v[2]=1 @(2, 4)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[2], b[2]) = (5, 5) is not adjacent to edge between u[2]=0 @(4, 4) and v[2]=1 @(2, 4)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 673 ms 29528 KB Output is correct
21 Correct 666 ms 29436 KB Output is correct
22 Correct 585 ms 29328 KB Output is correct
23 Correct 905 ms 24840 KB Output is correct
24 Correct 682 ms 19484 KB Output is correct
25 Correct 996 ms 21512 KB Output is correct
26 Correct 544 ms 21404 KB Output is correct
27 Correct 792 ms 28676 KB Output is correct
28 Correct 667 ms 28572 KB Output is correct
29 Correct 559 ms 28640 KB Output is correct
30 Correct 1072 ms 28772 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 27 ms 2688 KB Output is correct
33 Correct 124 ms 10388 KB Output is correct
34 Correct 498 ms 29568 KB Output is correct
35 Correct 14 ms 1380 KB Output is correct
36 Correct 91 ms 5780 KB Output is correct
37 Correct 315 ms 11348 KB Output is correct
38 Correct 176 ms 12480 KB Output is correct
39 Correct 283 ms 16492 KB Output is correct
40 Correct 327 ms 20824 KB Output is correct
41 Correct 405 ms 25152 KB Output is correct
42 Correct 935 ms 29572 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Incorrect 1 ms 212 KB Tree (a[0], b[0]) = (5, 5) is not adjacent to edge between u[0]=0 @(2, 4) and v[0]=1 @(4, 4)
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
17 Correct 733 ms 29092 KB Output is correct
18 Correct 651 ms 29168 KB Output is correct
19 Correct 548 ms 29388 KB Output is correct
20 Correct 988 ms 27940 KB Output is correct
21 Correct 829 ms 25124 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 72 ms 5268 KB Output is correct
24 Correct 31 ms 2516 KB Output is correct
25 Correct 146 ms 8320 KB Output is correct
26 Correct 294 ms 13436 KB Output is correct
27 Correct 244 ms 15012 KB Output is correct
28 Correct 323 ms 19008 KB Output is correct
29 Correct 409 ms 22376 KB Output is correct
30 Correct 487 ms 25752 KB Output is correct
31 Correct 751 ms 29588 KB Output is correct
32 Correct 636 ms 30236 KB Output is correct
33 Incorrect 431 ms 30216 KB Tree (a[199996], b[199996]) = (5, 5) is not adjacent to edge between u[199996]=74259 @(4, 4) and v[199996]=191221 @(2, 4)
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 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 262 ms 15380 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 71 ms 8272 KB Output is correct
12 Correct 19 ms 2872 KB Output is correct
13 Correct 47 ms 5340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 179 ms 15472 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[2], b[2]) = (5, 5) is not adjacent to edge between u[2]=0 @(4, 4) and v[2]=1 @(2, 4)
18 Halted 0 ms 0 KB -