Submission #733211

# Submission time Handle Problem Language Result Execution time Memory
733211 2023-04-30T08:57:18 Z kym Team Contest (JOI22_team) C++14
100 / 100
535 ms 73576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach 
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> void chmax(T& a, const T b) { a=max(a,b); }
template <typename T> void chmin(T& a, const T b) { a=min(a,b); }
const int MAXN = 150005;
array<int,3>A[MAXN];
int n;
unordered_map<int,vector<int>> VX;
unordered_map<int,vector<int>> VY;
unordered_map<int,vector<int>> VZ;

set<int> sX, sY, sZ;
bool done[MAXN];
int cury, curz;
int32_t main() 
{
	IAMSPEED
	cin >> n;
	FOR(i,1,n)cin>>A[i][0]>>A[i][1]>>A[i][2];
	FOR(i,1,n)sX.insert(A[i][0]);
	FOR(i,1,n)sY.insert(A[i][1]);
	FOR(i,1,n)sZ.insert(A[i][2]);

	FOR(i,1,n){
		VX[A[i][0]].pb(i);
		VY[A[i][1]].pb(i);
		VZ[A[i][2]].pb(i);
	}

	vector<int> yvals;
	for(auto x:sY)yvals.pb(x); // feed all of y-values into the Y set

	vector<int> zvals;
	for(auto x:sZ)zvals.pb(x);// feed the z-values into the Z set
	unordered_set<int> Yset, Zset;
	for(auto idx:VY[yvals.back()]){
		Yset.insert(idx);
	}
	cury=yvals.back();
	yvals.pop_back();

	for(auto idx:VZ[zvals.back()]){
		Zset.insert(idx);
		
	}
	curz=zvals.back();
	zvals.pop_back();


	vector<int> xvals;
	for(auto x:sX)xvals.pb(x);
	reverse(all(xvals));

	for(auto x_val:xvals){
		db(x_val);
		for(auto idx:VX[x_val]){
			db(idx);
			done[idx]=1;
		}
		
		bool found=0;
		while(found==0){
			db(found);

			while(Zset.size() && Yset.size()){

				int z=*Zset.begin();
				int y=*Yset.begin();
				if(done[z]){
					Zset.erase(z);
					continue;
				}
				if(done[y]){
					Yset.erase(y);
					continue;
				}
				if(Zset.find(y) != Zset.end()){
					done[y]=1;
					Yset.erase(y);
					Zset.erase(y);
					continue;
				}

				if(Yset.find(z) != Yset.end()){
					done[z]=1;
					Yset.erase(z);
					Zset.erase(z);
					continue;
				}
				found=1;
				break;
			}

			if(Yset.empty()){
				if(yvals.empty()){
					cout<<"-1\n";exit(0);
				}
				cury=yvals.back();
				yvals.pop_back();
				for(auto idx:VY[cury]){
					Yset.insert(idx);
				}
			}
			if(Zset.empty()){
				if(zvals.empty()){
					cout<<"-1\n";exit(0);
				}
				curz=zvals.back();
				zvals.pop_back();
				for(auto idx:VZ[curz]){
					Zset.insert(idx);
				}
			}
		}
		for(auto idx:VX[x_val]){
			if(A[idx][1]<cury && A[idx][2]<curz){
				db3(x_val,cury,curz);
				cout<<x_val+cury+curz<<'\n';exit(0);
			}
		}
	}




}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 7 ms 2260 KB Output is correct
27 Correct 6 ms 1636 KB Output is correct
28 Correct 5 ms 1508 KB Output is correct
29 Correct 7 ms 1340 KB Output is correct
30 Correct 4 ms 1108 KB Output is correct
31 Correct 3 ms 992 KB Output is correct
32 Correct 3 ms 740 KB Output is correct
33 Correct 4 ms 1236 KB Output is correct
34 Correct 8 ms 2220 KB Output is correct
35 Correct 1 ms 564 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 1124 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 42 ms 11016 KB Output is correct
12 Correct 40 ms 8536 KB Output is correct
13 Correct 31 ms 7544 KB Output is correct
14 Correct 81 ms 13468 KB Output is correct
15 Correct 58 ms 18320 KB Output is correct
16 Correct 65 ms 20460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 42 ms 11016 KB Output is correct
12 Correct 40 ms 8536 KB Output is correct
13 Correct 31 ms 7544 KB Output is correct
14 Correct 81 ms 13468 KB Output is correct
15 Correct 58 ms 18320 KB Output is correct
16 Correct 65 ms 20460 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 48 ms 9584 KB Output is correct
23 Correct 42 ms 8892 KB Output is correct
24 Correct 41 ms 7708 KB Output is correct
25 Correct 69 ms 11612 KB Output is correct
26 Correct 60 ms 18292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 42 ms 11016 KB Output is correct
12 Correct 40 ms 8536 KB Output is correct
13 Correct 31 ms 7544 KB Output is correct
14 Correct 81 ms 13468 KB Output is correct
15 Correct 58 ms 18320 KB Output is correct
16 Correct 65 ms 20460 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 48 ms 9584 KB Output is correct
23 Correct 42 ms 8892 KB Output is correct
24 Correct 41 ms 7708 KB Output is correct
25 Correct 69 ms 11612 KB Output is correct
26 Correct 60 ms 18292 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 62 ms 9800 KB Output is correct
35 Correct 75 ms 11100 KB Output is correct
36 Correct 63 ms 11036 KB Output is correct
37 Correct 78 ms 10912 KB Output is correct
38 Correct 82 ms 19044 KB Output is correct
39 Correct 38 ms 6716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 42 ms 11016 KB Output is correct
12 Correct 40 ms 8536 KB Output is correct
13 Correct 31 ms 7544 KB Output is correct
14 Correct 81 ms 13468 KB Output is correct
15 Correct 58 ms 18320 KB Output is correct
16 Correct 65 ms 20460 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 48 ms 9584 KB Output is correct
23 Correct 42 ms 8892 KB Output is correct
24 Correct 41 ms 7708 KB Output is correct
25 Correct 69 ms 11612 KB Output is correct
26 Correct 60 ms 18292 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 62 ms 9800 KB Output is correct
35 Correct 75 ms 11100 KB Output is correct
36 Correct 63 ms 11036 KB Output is correct
37 Correct 78 ms 10912 KB Output is correct
38 Correct 82 ms 19044 KB Output is correct
39 Correct 38 ms 6716 KB Output is correct
40 Correct 3 ms 1108 KB Output is correct
41 Correct 4 ms 992 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 4 ms 1120 KB Output is correct
44 Correct 91 ms 14040 KB Output is correct
45 Correct 110 ms 13188 KB Output is correct
46 Correct 115 ms 13720 KB Output is correct
47 Correct 132 ms 13316 KB Output is correct
48 Correct 83 ms 20552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 7 ms 2260 KB Output is correct
27 Correct 6 ms 1636 KB Output is correct
28 Correct 5 ms 1508 KB Output is correct
29 Correct 7 ms 1340 KB Output is correct
30 Correct 4 ms 1108 KB Output is correct
31 Correct 3 ms 992 KB Output is correct
32 Correct 3 ms 740 KB Output is correct
33 Correct 4 ms 1236 KB Output is correct
34 Correct 8 ms 2220 KB Output is correct
35 Correct 1 ms 564 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 1124 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 42 ms 11016 KB Output is correct
51 Correct 40 ms 8536 KB Output is correct
52 Correct 31 ms 7544 KB Output is correct
53 Correct 81 ms 13468 KB Output is correct
54 Correct 58 ms 18320 KB Output is correct
55 Correct 65 ms 20460 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 48 ms 9584 KB Output is correct
62 Correct 42 ms 8892 KB Output is correct
63 Correct 41 ms 7708 KB Output is correct
64 Correct 69 ms 11612 KB Output is correct
65 Correct 60 ms 18292 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 3 ms 724 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 62 ms 9800 KB Output is correct
74 Correct 75 ms 11100 KB Output is correct
75 Correct 63 ms 11036 KB Output is correct
76 Correct 78 ms 10912 KB Output is correct
77 Correct 82 ms 19044 KB Output is correct
78 Correct 38 ms 6716 KB Output is correct
79 Correct 3 ms 1108 KB Output is correct
80 Correct 4 ms 992 KB Output is correct
81 Correct 3 ms 1116 KB Output is correct
82 Correct 4 ms 1120 KB Output is correct
83 Correct 91 ms 14040 KB Output is correct
84 Correct 110 ms 13188 KB Output is correct
85 Correct 115 ms 13720 KB Output is correct
86 Correct 132 ms 13316 KB Output is correct
87 Correct 83 ms 20552 KB Output is correct
88 Correct 473 ms 73552 KB Output is correct
89 Correct 369 ms 44616 KB Output is correct
90 Correct 350 ms 50976 KB Output is correct
91 Correct 406 ms 39420 KB Output is correct
92 Correct 183 ms 23300 KB Output is correct
93 Correct 415 ms 47808 KB Output is correct
94 Correct 287 ms 33076 KB Output is correct
95 Correct 155 ms 36500 KB Output is correct
96 Correct 535 ms 73576 KB Output is correct
97 Correct 74 ms 23592 KB Output is correct
98 Correct 145 ms 31180 KB Output is correct
99 Correct 174 ms 31384 KB Output is correct