답안 #211739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211739 2020-03-21T06:15:09 Z zscoder 함박 스테이크 (JOI20_hamburg) C++17
21 / 100
3000 ms 12996 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int grp[222222];

vector<int> Xcoord,Ycoord;
int n,k; 
vector<ii> ans;
vector<pair<ii,ii> > vec;

void getpt(int gp)
{
	int minX = -1;
	int maxX = int(1e9)+1;
	int minY = -1;
	int maxY = int(1e9)+1;
	for(int i=0;i<n;i++)
	{
		if(grp[i]==gp)
		{
			maxX=min(maxX,vec[i].fi.se);
			minX=max(minX,vec[i].fi.fi);
			maxY=min(maxY,vec[i].se.se);
			minY=max(minY,vec[i].se.fi);
		}
	}
	if(maxX<minX||minX<0) maxX=minX=0;
	if(maxY<minY||minY<0) maxY=minY=0;
	//cerr<<gp<<' '<<minX<<' '<<maxX<<' '<<minY<<' '<<maxY<<'\n';
	ans.pb({Xcoord[minX],Ycoord[minY]});
}

vi adj[2222];

bool intersect(int i, int j)
{
	return (vec[i].fi.se>=vec[j].fi.fi&&vec[j].fi.se>=vec[i].fi.fi&&vec[i].se.se>=vec[j].se.fi&&vec[j].se.se>=vec[i].se.fi);
}

bool visited[2222];

void dfs(int u, int bit=1, int p=-1)
{
	visited[u]=1;
	for(int v:adj[u])
	{
		if(v==p) continue;
		if(bit==2&&((grp[u]&1)!=(grp[v]&1))) continue;
		if(!visited[v])
		{
			grp[v]=grp[u]^bit;
			dfs(v,bit,u);
		}
	}
}

pair<ii,ii> B[4];
pair<ii,ii> def = {{-1,int(1e9)},{-1,int(1e9)}};

pair<ii,ii> inter(pair<ii,ii> a, pair<ii,ii> b)
{
	pair<ii,ii> c;
	c.fi.fi = max(a.fi.fi,b.fi.fi);
	c.fi.se = min(a.fi.se,b.fi.se);
	c.se.fi = max(a.se.fi,b.se.fi);
	c.se.se = min(a.se.se,b.se.se);
	return c;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		Xcoord.pb(x1); Xcoord.pb(x2);
		Ycoord.pb(y1); Ycoord.pb(y2);
		vec.pb({{x1,x2},{y1,y2}});
	}
	sort(vec.begin(),vec.end());
	sort(Xcoord.begin(),Xcoord.end()); Xcoord.erase(unique(Xcoord.begin(),Xcoord.end()),Xcoord.end());
	sort(Ycoord.begin(),Ycoord.end()); Ycoord.erase(unique(Ycoord.begin(),Ycoord.end()),Ycoord.end());
	for(int i=0;i<vec.size();i++)
	{
		vec[i].fi.fi=lower_bound(Xcoord.begin(),Xcoord.end(),vec[i].fi.fi)-Xcoord.begin();
		vec[i].fi.se=lower_bound(Xcoord.begin(),Xcoord.end(),vec[i].fi.se)-Xcoord.begin();
		vec[i].se.fi=lower_bound(Ycoord.begin(),Ycoord.end(),vec[i].se.fi)-Ycoord.begin();
		vec[i].se.se=lower_bound(Ycoord.begin(),Ycoord.end(),vec[i].se.se)-Ycoord.begin();
		//cerr<<vec[i].fi.fi<<' '<<vec[i].fi.se<<' '<<vec[i].se.fi<<' '<<vec[i].se.se<<'\n';
	}
	vi p(n);
	for(int i=0;i<n;i++)
	{
		p[i]=i;
	}
	random_shuffle(p.begin(),p.end());
	while(1)
	{
		for(int i=0;i<k;i++) B[i]=def;
		set<int> bad;
		for(int i=0;i<n;i++)
		{
			grp[p[i]]=-1;
			for(int j=0;j<k;j++)
			{
				pair<ii,ii> tmp = inter(B[j],vec[p[i]]);
				if(tmp.fi.se<tmp.fi.fi||tmp.se.se<tmp.se.fi) continue;
				grp[p[i]]=j;
				B[j]=tmp;
				break;
			}
			if(grp[p[i]]==-1) bad.insert(p[i]);
		}
		if(bad.empty()) break;
		p.clear();
		for(int i=0;i<n;i++)
		{
			if(bad.find(i)==bad.end())
			{
				p.pb(i);
			}
		}
		random_shuffle(p.begin(),p.end());
		vi q;
		for(int x:bad)
		{
			q.pb(x);
		}
		random_shuffle(q.begin(),q.end());
		for(int x:q) p.pb(x);
		reverse(p.begin(),p.end());
	}
	for(int i=0;i<k;i++) getpt(i);
	for(ii x:ans)
	{
		cout<<x.fi<<' '<<x.se<<'\n';
	}
}

Compilation message

hamburg.cpp: In function 'int main()':
hamburg.cpp:102:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  for(int i=0;i<vec.size();i++)
      |              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 564 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 488 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 9 ms 564 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 12 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 8 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 6 ms 640 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 11 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 6 ms 512 KB Output is correct
40 Correct 10 ms 512 KB Output is correct
41 Correct 7 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 8 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 11 ms 512 KB Output is correct
50 Correct 4 ms 512 KB Output is correct
51 Correct 7 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 6 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 4 ms 512 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 4 ms 512 KB Output is correct
58 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 330 ms 8260 KB Output is correct
6 Correct 328 ms 8256 KB Output is correct
7 Correct 327 ms 8260 KB Output is correct
8 Correct 335 ms 8268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 402 ms 12740 KB Output is correct
6 Correct 344 ms 9028 KB Output is correct
7 Correct 346 ms 8904 KB Output is correct
8 Correct 432 ms 10856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 564 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 488 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 375 ms 9028 KB Output is correct
14 Correct 369 ms 8372 KB Output is correct
15 Correct 368 ms 8776 KB Output is correct
16 Correct 363 ms 8492 KB Output is correct
17 Correct 336 ms 8384 KB Output is correct
18 Correct 337 ms 8396 KB Output is correct
19 Correct 353 ms 8792 KB Output is correct
20 Correct 362 ms 9164 KB Output is correct
21 Correct 419 ms 9940 KB Output is correct
22 Correct 362 ms 10180 KB Output is correct
23 Correct 768 ms 10948 KB Output is correct
24 Correct 370 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 4 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 9 ms 564 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 7 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 12 ms 512 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 8 ms 512 KB Output is correct
28 Correct 7 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 6 ms 640 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 11 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 6 ms 512 KB Output is correct
40 Correct 10 ms 512 KB Output is correct
41 Correct 7 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 8 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 4 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 11 ms 512 KB Output is correct
50 Correct 4 ms 512 KB Output is correct
51 Correct 7 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 6 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 4 ms 512 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 4 ms 512 KB Output is correct
58 Correct 3 ms 512 KB Output is correct
59 Correct 366 ms 9084 KB Output is correct
60 Correct 429 ms 8652 KB Output is correct
61 Correct 382 ms 10440 KB Output is correct
62 Correct 353 ms 8312 KB Output is correct
63 Correct 351 ms 8652 KB Output is correct
64 Correct 324 ms 8264 KB Output is correct
65 Correct 390 ms 8784 KB Output is correct
66 Correct 827 ms 9724 KB Output is correct
67 Correct 395 ms 9756 KB Output is correct
68 Correct 491 ms 10300 KB Output is correct
69 Correct 372 ms 9848 KB Output is correct
70 Correct 1875 ms 10360 KB Output is correct
71 Correct 500 ms 9264 KB Output is correct
72 Correct 649 ms 9924 KB Output is correct
73 Correct 1251 ms 12388 KB Output is correct
74 Correct 393 ms 10420 KB Output is correct
75 Correct 365 ms 9408 KB Output is correct
76 Correct 688 ms 10436 KB Output is correct
77 Correct 1040 ms 10568 KB Output is correct
78 Correct 1022 ms 10548 KB Output is correct
79 Correct 475 ms 9540 KB Output is correct
80 Correct 516 ms 9676 KB Output is correct
81 Correct 347 ms 9028 KB Output is correct
82 Correct 492 ms 10308 KB Output is correct
83 Correct 2025 ms 12380 KB Output is correct
84 Correct 1004 ms 9644 KB Output is correct
85 Correct 389 ms 10472 KB Output is correct
86 Correct 363 ms 9284 KB Output is correct
87 Correct 512 ms 10804 KB Output is correct
88 Correct 578 ms 10728 KB Output is correct
89 Correct 1033 ms 9420 KB Output is correct
90 Correct 379 ms 9436 KB Output is correct
91 Correct 379 ms 9756 KB Output is correct
92 Correct 350 ms 9516 KB Output is correct
93 Correct 1165 ms 12996 KB Output is correct
94 Correct 1202 ms 10564 KB Output is correct
95 Correct 659 ms 10436 KB Output is correct
96 Correct 418 ms 10184 KB Output is correct
97 Correct 387 ms 9464 KB Output is correct
98 Correct 354 ms 8928 KB Output is correct
99 Correct 1068 ms 9712 KB Output is correct
100 Correct 375 ms 10404 KB Output is correct
101 Correct 371 ms 9412 KB Output is correct
102 Correct 1127 ms 10704 KB Output is correct
103 Correct 585 ms 11208 KB Output is correct
104 Correct 1395 ms 10612 KB Output is correct
105 Correct 702 ms 10604 KB Output is correct
106 Correct 483 ms 10292 KB Output is correct
107 Correct 697 ms 9684 KB Output is correct
108 Correct 618 ms 10204 KB Output is correct
109 Correct 631 ms 10880 KB Output is correct
110 Correct 570 ms 9796 KB Output is correct
111 Correct 868 ms 10696 KB Output is correct
112 Correct 937 ms 11256 KB Output is correct
113 Correct 328 ms 8264 KB Output is correct
114 Correct 328 ms 8220 KB Output is correct
115 Correct 398 ms 8772 KB Output is correct
116 Correct 393 ms 8812 KB Output is correct
117 Execution timed out 3073 ms 10948 KB Time limit exceeded
118 Halted 0 ms 0 KB -