답안 #754245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754245 2023-06-07T10:22:11 Z tolbi 분수 공원 (IOI21_parks) C++17
55 / 100
1290 ms 51956 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename X, size_t Y> istream& operator>>(istream& in, array<X,Y> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename T> vector<int32_t> normalize(vector<T> &arr){vector<int> rv;rv.resize(arr.size());for (int i = 0; i < rv.size(); ++i){rv[i]=arr[i];}return rv;}
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#include "parks.h"
struct DSU{
	vector<int> par;
	DSU(int n){
		par.resize(n);
		iota(par.begin(), par.end(), 0ll);
	}
	int find(int node){
		if (par[node]==node) return node;
		return par[node]=find(par[node]);
	}
	void merge(int a, int b){
		a=find(a);
		b=find(b);
		if (ayahya()%2) swap(a,b);
		par[a]=b;
	}
};
int construct_roads(vector<int> x, vector<int> y) {
	map<pair<int,int>,int> mp;
	int n = x.size();
	for (int i = 0; i < n; ++i)
	{
		mp[{x[i],y[i]}]=i;
	}
	map<pair<int,int>,int> dikey;
	map<pair<int,int>,int> yatay;
	vector<bool> yat;
	vector<int> u;
	vector<int> v;
	vector<int> a;
	vector<int> b;
	DSU dsu(n);
	for (int i = 0; i < n; i++){
		int xv = x[i];
		int yv = y[i];
		if (mp.count({xv+2,yv})){
			if (dsu.find(i)!=dsu.find(mp[{xv+2,yv}])){
				dsu.merge(i,mp[{xv+2,yv}]);
				yatay[{xv,yv}]=u.size();
				u.push_back(i);
				v.push_back(mp[{xv+2,yv}]);
				yat.push_back(true);
				a.push_back(-23);
				b.push_back(-23);
			}
		}
		if (mp.count({xv,yv+2})){
			if (dsu.find(i)!=dsu.find(mp[{xv,yv+2}])){
				dsu.merge(i,mp[{xv,yv+2}]);
				dikey[{xv,yv}]=u.size();
				u.push_back(i);
				v.push_back(mp[{xv,yv+2}]);
				yat.push_back(false);
				a.push_back(-23);
				b.push_back(-23);
			}
		}
	}
	if (u.size()!=n-1) return 0;
	map<pair<int,int>,bool> kap;
	int mini = *min_element(x.begin(), x.end());
	int minj = *min_element(y.begin(), y.end());
	int mani = *max_element(x.begin(), x.end());
	int manj = *max_element(y.begin(), y.end());
	for (int i = 0; i < u.size(); i++){
		if (x[u[i]]==mini && !yat[i]){
			a[i]=x[u[i]]-1;
			b[i]=y[u[i]]+1;
			continue;
		}
		if (x[u[i]]==mani && !yat[i]){
			a[i]=x[u[i]]+1;
			b[i]=y[u[i]]+1;
			continue;
		}
		int ed = i;
		while (true){
			if (a[ed]!=-23) break;
			if (yat[ed]){
				if (!kap[{x[u[ed]]+1,y[u[ed]]+1}]){
					kap[{x[u[ed]]+1,y[u[ed]]+1}]=true;
					a[ed]=x[u[ed]]+1;
					b[ed]=y[u[ed]]+1;
				}
				else {
					kap[{x[u[ed]]+1,y[u[ed]]-1}]=true;
					a[ed]=x[u[ed]]+1;
					b[ed]=y[u[ed]]-1;
				}
			}
			else {
				if (!kap[{x[u[ed]]+1,y[u[ed]]+1}]){
					kap[{x[u[ed]]+1,y[u[ed]]+1}]=true;
					a[ed]=x[u[ed]]+1;
					b[ed]=y[u[ed]]+1;
				}
				else {
					kap[{x[u[ed]]-1,y[u[ed]]+1}]=true;
					a[ed]=x[u[ed]]-1;
					b[ed]=y[u[ed]]+1;
				}
			}
			pair<int,int> pr;
			pr={a[ed]-1,b[ed]-1};
			if (yatay.count(pr) && yatay[pr]!=ed){
				ed=yatay[pr];
				continue;
			}
			pr={a[ed]-1,b[ed]+1};
			if (yatay.count(pr) && yatay[pr]!=ed){
				ed=yatay[pr];
				continue;
			}			
			pr={a[ed]-1,b[ed]-1};
			if (dikey.count(pr) && dikey[pr]!=ed){
				ed=dikey[pr];
				continue;
			}			
			pr={a[ed]+1,b[ed]-1};
			if (dikey.count(pr) && dikey[pr]!=ed){
				ed=dikey[pr];
				continue;
			}
		}
	}
	build(u,v,a,b);
	return 1;
}

Compilation message

parks.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:95:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   95 |  if (u.size()!=n-1) return 0;
      |      ~~~~~~~~^~~~~
parks.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |  for (int i = 0; i < u.size(); i++){
      |                  ~~^~~~~~~~~~
parks.cpp:98:6: warning: unused variable 'minj' [-Wunused-variable]
   98 |  int minj = *min_element(y.begin(), y.end());
      |      ^~~~
parks.cpp:100:6: warning: unused variable 'manj' [-Wunused-variable]
  100 |  int manj = *max_element(y.begin(), y.end());
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 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 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 883 ms 45172 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 260 ms 18364 KB Output is correct
29 Correct 447 ms 27308 KB Output is correct
30 Correct 704 ms 36280 KB Output is correct
31 Correct 904 ms 45188 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 312 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 820 KB Output is correct
45 Correct 388 ms 23204 KB Output is correct
46 Correct 642 ms 33560 KB Output is correct
47 Correct 641 ms 33712 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 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 883 ms 45172 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 260 ms 18364 KB Output is correct
29 Correct 447 ms 27308 KB Output is correct
30 Correct 704 ms 36280 KB Output is correct
31 Correct 904 ms 45188 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 312 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 820 KB Output is correct
45 Correct 388 ms 23204 KB Output is correct
46 Correct 642 ms 33560 KB Output is correct
47 Correct 641 ms 33712 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 304 KB Output is correct
51 Correct 1 ms 300 KB Output is correct
52 Correct 1 ms 304 KB Output is correct
53 Incorrect 1 ms 212 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 3
54 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 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 836 ms 51760 KB Output is correct
21 Correct 969 ms 51696 KB Output is correct
22 Correct 849 ms 51956 KB Output is correct
23 Correct 679 ms 41608 KB Output is correct
24 Correct 258 ms 17168 KB Output is correct
25 Correct 693 ms 32800 KB Output is correct
26 Correct 656 ms 32916 KB Output is correct
27 Correct 1164 ms 51808 KB Output is correct
28 Correct 1198 ms 51784 KB Output is correct
29 Correct 1268 ms 51856 KB Output is correct
30 Correct 1273 ms 51780 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 43 ms 4392 KB Output is correct
33 Correct 112 ms 9528 KB Output is correct
34 Correct 919 ms 51724 KB Output is correct
35 Correct 15 ms 2060 KB Output is correct
36 Correct 110 ms 8844 KB Output is correct
37 Correct 296 ms 17428 KB Output is correct
38 Correct 388 ms 21108 KB Output is correct
39 Correct 557 ms 28728 KB Output is correct
40 Correct 728 ms 36280 KB Output is correct
41 Correct 1033 ms 44068 KB Output is correct
42 Correct 1163 ms 51788 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 0 ms 300 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 3 ms 596 KB Output is correct
55 Correct 4 ms 724 KB Output is correct
56 Correct 332 ms 23188 KB Output is correct
57 Correct 574 ms 33508 KB Output is correct
58 Correct 585 ms 33528 KB Output is correct
59 Correct 1 ms 304 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 587 ms 39052 KB Output is correct
63 Correct 633 ms 39208 KB Output is correct
64 Correct 604 ms 38924 KB Output is correct
65 Correct 5 ms 980 KB Output is correct
66 Correct 11 ms 1620 KB Output is correct
67 Correct 387 ms 24040 KB Output is correct
68 Correct 713 ms 35768 KB Output is correct
69 Correct 985 ms 47724 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 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 KB Output is correct
17 Correct 884 ms 45528 KB Output is correct
18 Correct 917 ms 48688 KB Output is correct
19 Correct 806 ms 51824 KB Output is correct
20 Correct 1171 ms 50480 KB Output is correct
21 Correct 984 ms 45304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 99 ms 8792 KB Output is correct
24 Correct 33 ms 3740 KB Output is correct
25 Correct 166 ms 12432 KB Output is correct
26 Correct 312 ms 20544 KB Output is correct
27 Correct 484 ms 26156 KB Output is correct
28 Correct 643 ms 32536 KB Output is correct
29 Correct 812 ms 38840 KB Output is correct
30 Correct 1028 ms 44800 KB Output is correct
31 Correct 1290 ms 51276 KB Output is correct
32 Correct 926 ms 45732 KB Output is correct
33 Correct 585 ms 38616 KB Output is correct
34 Correct 6 ms 1108 KB Output is correct
35 Correct 14 ms 1748 KB Output is correct
36 Correct 358 ms 23640 KB Output is correct
37 Correct 639 ms 35396 KB Output is correct
38 Correct 929 ms 47156 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 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 239 ms 19720 KB Output is correct
10 Correct 13 ms 2388 KB Output is correct
11 Correct 76 ms 10812 KB Output is correct
12 Correct 20 ms 3464 KB Output is correct
13 Correct 49 ms 7636 KB Output is correct
14 Correct 2 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 240 ms 19748 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 883 ms 45172 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 260 ms 18364 KB Output is correct
29 Correct 447 ms 27308 KB Output is correct
30 Correct 704 ms 36280 KB Output is correct
31 Correct 904 ms 45188 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 312 KB Output is correct
40 Correct 1 ms 296 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 820 KB Output is correct
45 Correct 388 ms 23204 KB Output is correct
46 Correct 642 ms 33560 KB Output is correct
47 Correct 641 ms 33712 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 304 KB Output is correct
51 Correct 1 ms 300 KB Output is correct
52 Correct 1 ms 304 KB Output is correct
53 Incorrect 1 ms 212 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 3
54 Halted 0 ms 0 KB -