Submission #754242

# Submission time Handle Problem Language Result Execution time Memory
754242 2023-06-07T10:14:18 Z tolbi Fountain Parks (IOI21_parks) C++17
55 / 100
1332 ms 53724 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;
	for (int i = 0; i < u.size(); i++){
		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:97:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |  for (int i = 0; i < u.size(); i++){
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 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 212 KB Output is correct
23 Correct 1066 ms 52192 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 568 KB Output is correct
26 Correct 4 ms 736 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 295 ms 21320 KB Output is correct
29 Correct 525 ms 31908 KB Output is correct
30 Correct 771 ms 41916 KB Output is correct
31 Correct 1029 ms 52148 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 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 0 ms 212 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 300 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 451 ms 26528 KB Output is correct
46 Correct 700 ms 38084 KB Output is correct
47 Correct 733 ms 38044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 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 212 KB Output is correct
23 Correct 1066 ms 52192 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 568 KB Output is correct
26 Correct 4 ms 736 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 295 ms 21320 KB Output is correct
29 Correct 525 ms 31908 KB Output is correct
30 Correct 771 ms 41916 KB Output is correct
31 Correct 1029 ms 52148 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 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 0 ms 212 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 300 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 451 ms 26528 KB Output is correct
46 Correct 700 ms 38084 KB Output is correct
47 Correct 733 ms 38044 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 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 811 ms 52356 KB Output is correct
21 Correct 947 ms 52160 KB Output is correct
22 Correct 772 ms 51996 KB Output is correct
23 Correct 826 ms 44376 KB Output is correct
24 Correct 319 ms 18004 KB Output is correct
25 Correct 729 ms 33564 KB Output is correct
26 Correct 683 ms 33612 KB Output is correct
27 Correct 1105 ms 51860 KB Output is correct
28 Correct 1277 ms 51824 KB Output is correct
29 Correct 1155 ms 51900 KB Output is correct
30 Correct 1241 ms 51804 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 42 ms 4376 KB Output is correct
33 Correct 114 ms 9668 KB Output is correct
34 Correct 828 ms 53692 KB Output is correct
35 Correct 14 ms 1976 KB Output is correct
36 Correct 101 ms 8944 KB Output is correct
37 Correct 256 ms 17736 KB Output is correct
38 Correct 370 ms 21788 KB Output is correct
39 Correct 607 ms 29736 KB Output is correct
40 Correct 721 ms 37640 KB Output is correct
41 Correct 1093 ms 45856 KB Output is correct
42 Correct 1332 ms 53724 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 304 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 304 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 308 KB Output is correct
53 Correct 0 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 445 ms 26552 KB Output is correct
57 Correct 796 ms 38676 KB Output is correct
58 Correct 811 ms 38436 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1058 ms 53140 KB Output is correct
63 Correct 1030 ms 52948 KB Output is correct
64 Correct 1025 ms 52708 KB Output is correct
65 Correct 6 ms 980 KB Output is correct
66 Correct 11 ms 1664 KB Output is correct
67 Correct 469 ms 26592 KB Output is correct
68 Correct 848 ms 39780 KB Output is correct
69 Correct 1209 ms 52920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
17 Correct 1060 ms 51728 KB Output is correct
18 Correct 1031 ms 51888 KB Output is correct
19 Correct 913 ms 51988 KB Output is correct
20 Correct 1212 ms 51712 KB Output is correct
21 Correct 1029 ms 46332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 99 ms 8920 KB Output is correct
24 Correct 35 ms 3768 KB Output is correct
25 Correct 185 ms 12392 KB Output is correct
26 Correct 377 ms 21076 KB Output is correct
27 Correct 472 ms 27036 KB Output is correct
28 Correct 714 ms 33840 KB Output is correct
29 Correct 919 ms 40492 KB Output is correct
30 Correct 1271 ms 46836 KB Output is correct
31 Correct 1285 ms 53716 KB Output is correct
32 Correct 1167 ms 52848 KB Output is correct
33 Correct 947 ms 52912 KB Output is correct
34 Correct 6 ms 1108 KB Output is correct
35 Correct 13 ms 1876 KB Output is correct
36 Correct 433 ms 26496 KB Output is correct
37 Correct 833 ms 39848 KB Output is correct
38 Correct 1216 ms 52880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 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 346 ms 26524 KB Output is correct
10 Correct 19 ms 3020 KB Output is correct
11 Correct 128 ms 14440 KB Output is correct
12 Correct 27 ms 4428 KB Output is correct
13 Correct 50 ms 7744 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 363 ms 26688 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 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 212 KB Output is correct
23 Correct 1066 ms 52192 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 568 KB Output is correct
26 Correct 4 ms 736 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 295 ms 21320 KB Output is correct
29 Correct 525 ms 31908 KB Output is correct
30 Correct 771 ms 41916 KB Output is correct
31 Correct 1029 ms 52148 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 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 0 ms 212 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 300 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 451 ms 26528 KB Output is correct
46 Correct 700 ms 38084 KB Output is correct
47 Correct 733 ms 38044 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 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 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 -