Submission #551669

# Submission time Handle Problem Language Result Execution time Memory
551669 2022-04-21T09:36:28 Z kshitij_sodani Team Contest (JOI22_team) C++14
100 / 100
1734 ms 729668 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'
const llo mod=1e9+7;
llo n;
llo it[200001][3];
multiset<llo> pre[3];
set<pair<llo,llo>> pre2[1500001][3][3];
llo ma[3];
llo vis[200001];
map<llo,llo> tt2[200001];
void remove(llo i){
	vis[i]=1;
	//cout<<i<<":"<<endl;
	for(llo j=0;j<3;j++){
		auto jj=pre[j].find(it[i][j]);
		pre[j].erase(jj);
	}
	/*for(int j=0;j<3;j++){
		for(auto i:pre[j]){
			cout<<i<<',';
		}
		cout<<endl;
	}*/
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;

	for(llo i=0;i<n;i++){
		for(llo j=0;j<3;j++){
			cin>>it[i][j];
			
		}
	}
	for(llo j=0;j<3;j++){
		map<llo,llo> ss;
		for(llo i=0;i<n;i++){
			ss[it[i][j]]++;
		}
		map<llo,llo> tt;
		llo ind=0;
		for(auto i:ss){
			tt[i.a]=ind;
			ind++;
		}
		for(llo i=0;i<n;i++){
			tt2[j][tt[it[i][j]]]=it[i][j];
			it[i][j]=tt[it[i][j]];
			pre[j].insert(it[i][j]);
		}
	}
	for(llo i=0;i<n;i++){
		for(llo j=0;j<3;j++){
			for(llo k=j+1;k<3;k++){
				pre2[it[i][j]][j][k].insert({it[i][k],i});
			}
		}
	}
	while(true){
		if(pre[0].size()<3){
			cout<<-1<<endl;
			return 0;
		}
		for(llo i=0;i<3;i++){
			auto j=pre[i].end();
			j--;
			ma[i]=(*j);
		}
		llo st=0;
		for(llo j=0;j<2;j++){
			for(llo k=j+1;k<3;k++){
				while(pre2[ma[j]][j][k].size()){
					auto jj=pre2[ma[j]][j][k].end();
					jj--;
					pair<llo,llo> no=(*jj);
					if(vis[no.b]==1){
						pre2[ma[j]][j][k].erase(jj);
						continue;
					}
					if(no.a==ma[k]){
						st++;
						vis[no.b]=1;
						remove(no.b);
						pre2[ma[j]][j][k].erase(jj);
						continue;
					}
					break;
				}
			}
		}
		if(st==0){
			llo su=0;
			for(int j=0;j<3;j++){
				su+=tt2[j][ma[j]];
			}
			cout<<su<<endl;
			return 0;
		}
	}
/*	while(true){
		if(pre[0].size()<3){
			cout<<-1<<endl;
			return 0;
		}
		for(llo i=0;i<3;i++){
			auto j=pre[i].end();
			j--;
			ma[i]=(*j);
		}
		llo st=0;
		for(llo i=0;i<n;i++){
			llo co=0;
			if(vis[i]){
				continue;
			}

			for(llo j=0;j<3;j++){
				if(it[i][j]==ma[j]){
					co++;
				}
			}
			if(co>1){
				for(llo j=0;j<3;j++){
					auto ii=pre[j].find(it[i][j]);
					pre[j].erase(ii);

				}
				vis[i]=1;
				st++;
			}
		}
		if(st==0){
			cout<<ma[0]+ma[2]+ma[1]<<endl;
			return 0;
		}
	}

*/





	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 437 ms 643680 KB Output is correct
2 Correct 301 ms 643764 KB Output is correct
3 Correct 319 ms 643720 KB Output is correct
4 Correct 313 ms 643716 KB Output is correct
5 Correct 326 ms 643700 KB Output is correct
6 Correct 291 ms 643764 KB Output is correct
7 Correct 298 ms 643676 KB Output is correct
8 Correct 304 ms 643760 KB Output is correct
9 Correct 298 ms 643740 KB Output is correct
10 Correct 290 ms 643724 KB Output is correct
11 Correct 329 ms 643756 KB Output is correct
12 Correct 303 ms 643748 KB Output is correct
13 Correct 294 ms 643696 KB Output is correct
14 Correct 360 ms 643924 KB Output is correct
15 Correct 322 ms 643868 KB Output is correct
16 Correct 351 ms 643840 KB Output is correct
17 Correct 320 ms 643844 KB Output is correct
18 Correct 300 ms 643924 KB Output is correct
19 Correct 348 ms 643784 KB Output is correct
20 Correct 302 ms 643772 KB Output is correct
21 Correct 296 ms 643904 KB Output is correct
22 Correct 289 ms 643924 KB Output is correct
23 Correct 316 ms 643848 KB Output is correct
24 Correct 290 ms 643944 KB Output is correct
25 Correct 283 ms 643776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 643680 KB Output is correct
2 Correct 301 ms 643764 KB Output is correct
3 Correct 319 ms 643720 KB Output is correct
4 Correct 313 ms 643716 KB Output is correct
5 Correct 326 ms 643700 KB Output is correct
6 Correct 291 ms 643764 KB Output is correct
7 Correct 298 ms 643676 KB Output is correct
8 Correct 304 ms 643760 KB Output is correct
9 Correct 298 ms 643740 KB Output is correct
10 Correct 290 ms 643724 KB Output is correct
11 Correct 329 ms 643756 KB Output is correct
12 Correct 303 ms 643748 KB Output is correct
13 Correct 294 ms 643696 KB Output is correct
14 Correct 360 ms 643924 KB Output is correct
15 Correct 322 ms 643868 KB Output is correct
16 Correct 351 ms 643840 KB Output is correct
17 Correct 320 ms 643844 KB Output is correct
18 Correct 300 ms 643924 KB Output is correct
19 Correct 348 ms 643784 KB Output is correct
20 Correct 302 ms 643772 KB Output is correct
21 Correct 296 ms 643904 KB Output is correct
22 Correct 289 ms 643924 KB Output is correct
23 Correct 316 ms 643848 KB Output is correct
24 Correct 290 ms 643944 KB Output is correct
25 Correct 283 ms 643776 KB Output is correct
26 Correct 351 ms 645948 KB Output is correct
27 Correct 298 ms 645620 KB Output is correct
28 Correct 311 ms 645640 KB Output is correct
29 Correct 298 ms 645592 KB Output is correct
30 Correct 308 ms 645024 KB Output is correct
31 Correct 300 ms 645424 KB Output is correct
32 Correct 314 ms 645212 KB Output is correct
33 Correct 305 ms 645416 KB Output is correct
34 Correct 319 ms 646100 KB Output is correct
35 Correct 308 ms 644044 KB Output is correct
36 Correct 296 ms 644156 KB Output is correct
37 Correct 328 ms 645412 KB Output is correct
38 Correct 316 ms 645388 KB Output is correct
39 Correct 314 ms 644672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 643676 KB Output is correct
2 Correct 323 ms 643668 KB Output is correct
3 Correct 315 ms 643772 KB Output is correct
4 Correct 309 ms 643752 KB Output is correct
5 Correct 315 ms 643808 KB Output is correct
6 Correct 285 ms 643724 KB Output is correct
7 Correct 296 ms 643908 KB Output is correct
8 Correct 294 ms 643744 KB Output is correct
9 Correct 286 ms 643720 KB Output is correct
10 Correct 296 ms 643672 KB Output is correct
11 Correct 601 ms 698028 KB Output is correct
12 Correct 506 ms 680092 KB Output is correct
13 Correct 480 ms 688428 KB Output is correct
14 Correct 603 ms 698076 KB Output is correct
15 Correct 558 ms 697928 KB Output is correct
16 Correct 603 ms 698004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 643676 KB Output is correct
2 Correct 323 ms 643668 KB Output is correct
3 Correct 315 ms 643772 KB Output is correct
4 Correct 309 ms 643752 KB Output is correct
5 Correct 315 ms 643808 KB Output is correct
6 Correct 285 ms 643724 KB Output is correct
7 Correct 296 ms 643908 KB Output is correct
8 Correct 294 ms 643744 KB Output is correct
9 Correct 286 ms 643720 KB Output is correct
10 Correct 296 ms 643672 KB Output is correct
11 Correct 601 ms 698028 KB Output is correct
12 Correct 506 ms 680092 KB Output is correct
13 Correct 480 ms 688428 KB Output is correct
14 Correct 603 ms 698076 KB Output is correct
15 Correct 558 ms 697928 KB Output is correct
16 Correct 603 ms 698004 KB Output is correct
17 Correct 306 ms 643720 KB Output is correct
18 Correct 299 ms 643688 KB Output is correct
19 Correct 324 ms 643892 KB Output is correct
20 Correct 328 ms 643900 KB Output is correct
21 Correct 338 ms 644500 KB Output is correct
22 Correct 741 ms 697936 KB Output is correct
23 Correct 693 ms 696924 KB Output is correct
24 Correct 658 ms 683220 KB Output is correct
25 Correct 747 ms 698044 KB Output is correct
26 Correct 600 ms 698156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 643676 KB Output is correct
2 Correct 323 ms 643668 KB Output is correct
3 Correct 315 ms 643772 KB Output is correct
4 Correct 309 ms 643752 KB Output is correct
5 Correct 315 ms 643808 KB Output is correct
6 Correct 285 ms 643724 KB Output is correct
7 Correct 296 ms 643908 KB Output is correct
8 Correct 294 ms 643744 KB Output is correct
9 Correct 286 ms 643720 KB Output is correct
10 Correct 296 ms 643672 KB Output is correct
11 Correct 601 ms 698028 KB Output is correct
12 Correct 506 ms 680092 KB Output is correct
13 Correct 480 ms 688428 KB Output is correct
14 Correct 603 ms 698076 KB Output is correct
15 Correct 558 ms 697928 KB Output is correct
16 Correct 603 ms 698004 KB Output is correct
17 Correct 306 ms 643720 KB Output is correct
18 Correct 299 ms 643688 KB Output is correct
19 Correct 324 ms 643892 KB Output is correct
20 Correct 328 ms 643900 KB Output is correct
21 Correct 338 ms 644500 KB Output is correct
22 Correct 741 ms 697936 KB Output is correct
23 Correct 693 ms 696924 KB Output is correct
24 Correct 658 ms 683220 KB Output is correct
25 Correct 747 ms 698044 KB Output is correct
26 Correct 600 ms 698156 KB Output is correct
27 Correct 293 ms 643776 KB Output is correct
28 Correct 323 ms 643824 KB Output is correct
29 Correct 297 ms 643820 KB Output is correct
30 Correct 300 ms 643888 KB Output is correct
31 Correct 315 ms 645324 KB Output is correct
32 Correct 299 ms 644092 KB Output is correct
33 Correct 311 ms 644036 KB Output is correct
34 Correct 863 ms 694524 KB Output is correct
35 Correct 930 ms 693128 KB Output is correct
36 Correct 1033 ms 698132 KB Output is correct
37 Correct 1048 ms 697708 KB Output is correct
38 Correct 676 ms 696876 KB Output is correct
39 Correct 526 ms 676592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 643676 KB Output is correct
2 Correct 323 ms 643668 KB Output is correct
3 Correct 315 ms 643772 KB Output is correct
4 Correct 309 ms 643752 KB Output is correct
5 Correct 315 ms 643808 KB Output is correct
6 Correct 285 ms 643724 KB Output is correct
7 Correct 296 ms 643908 KB Output is correct
8 Correct 294 ms 643744 KB Output is correct
9 Correct 286 ms 643720 KB Output is correct
10 Correct 296 ms 643672 KB Output is correct
11 Correct 601 ms 698028 KB Output is correct
12 Correct 506 ms 680092 KB Output is correct
13 Correct 480 ms 688428 KB Output is correct
14 Correct 603 ms 698076 KB Output is correct
15 Correct 558 ms 697928 KB Output is correct
16 Correct 603 ms 698004 KB Output is correct
17 Correct 306 ms 643720 KB Output is correct
18 Correct 299 ms 643688 KB Output is correct
19 Correct 324 ms 643892 KB Output is correct
20 Correct 328 ms 643900 KB Output is correct
21 Correct 338 ms 644500 KB Output is correct
22 Correct 741 ms 697936 KB Output is correct
23 Correct 693 ms 696924 KB Output is correct
24 Correct 658 ms 683220 KB Output is correct
25 Correct 747 ms 698044 KB Output is correct
26 Correct 600 ms 698156 KB Output is correct
27 Correct 293 ms 643776 KB Output is correct
28 Correct 323 ms 643824 KB Output is correct
29 Correct 297 ms 643820 KB Output is correct
30 Correct 300 ms 643888 KB Output is correct
31 Correct 315 ms 645324 KB Output is correct
32 Correct 299 ms 644092 KB Output is correct
33 Correct 311 ms 644036 KB Output is correct
34 Correct 863 ms 694524 KB Output is correct
35 Correct 930 ms 693128 KB Output is correct
36 Correct 1033 ms 698132 KB Output is correct
37 Correct 1048 ms 697708 KB Output is correct
38 Correct 676 ms 696876 KB Output is correct
39 Correct 526 ms 676592 KB Output is correct
40 Correct 295 ms 644988 KB Output is correct
41 Correct 310 ms 645452 KB Output is correct
42 Correct 317 ms 645324 KB Output is correct
43 Correct 298 ms 645552 KB Output is correct
44 Correct 975 ms 697660 KB Output is correct
45 Correct 1103 ms 698756 KB Output is correct
46 Correct 1197 ms 699956 KB Output is correct
47 Correct 1228 ms 700620 KB Output is correct
48 Correct 807 ms 700036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 643680 KB Output is correct
2 Correct 301 ms 643764 KB Output is correct
3 Correct 319 ms 643720 KB Output is correct
4 Correct 313 ms 643716 KB Output is correct
5 Correct 326 ms 643700 KB Output is correct
6 Correct 291 ms 643764 KB Output is correct
7 Correct 298 ms 643676 KB Output is correct
8 Correct 304 ms 643760 KB Output is correct
9 Correct 298 ms 643740 KB Output is correct
10 Correct 290 ms 643724 KB Output is correct
11 Correct 329 ms 643756 KB Output is correct
12 Correct 303 ms 643748 KB Output is correct
13 Correct 294 ms 643696 KB Output is correct
14 Correct 360 ms 643924 KB Output is correct
15 Correct 322 ms 643868 KB Output is correct
16 Correct 351 ms 643840 KB Output is correct
17 Correct 320 ms 643844 KB Output is correct
18 Correct 300 ms 643924 KB Output is correct
19 Correct 348 ms 643784 KB Output is correct
20 Correct 302 ms 643772 KB Output is correct
21 Correct 296 ms 643904 KB Output is correct
22 Correct 289 ms 643924 KB Output is correct
23 Correct 316 ms 643848 KB Output is correct
24 Correct 290 ms 643944 KB Output is correct
25 Correct 283 ms 643776 KB Output is correct
26 Correct 351 ms 645948 KB Output is correct
27 Correct 298 ms 645620 KB Output is correct
28 Correct 311 ms 645640 KB Output is correct
29 Correct 298 ms 645592 KB Output is correct
30 Correct 308 ms 645024 KB Output is correct
31 Correct 300 ms 645424 KB Output is correct
32 Correct 314 ms 645212 KB Output is correct
33 Correct 305 ms 645416 KB Output is correct
34 Correct 319 ms 646100 KB Output is correct
35 Correct 308 ms 644044 KB Output is correct
36 Correct 296 ms 644156 KB Output is correct
37 Correct 328 ms 645412 KB Output is correct
38 Correct 316 ms 645388 KB Output is correct
39 Correct 314 ms 644672 KB Output is correct
40 Correct 320 ms 643676 KB Output is correct
41 Correct 323 ms 643668 KB Output is correct
42 Correct 315 ms 643772 KB Output is correct
43 Correct 309 ms 643752 KB Output is correct
44 Correct 315 ms 643808 KB Output is correct
45 Correct 285 ms 643724 KB Output is correct
46 Correct 296 ms 643908 KB Output is correct
47 Correct 294 ms 643744 KB Output is correct
48 Correct 286 ms 643720 KB Output is correct
49 Correct 296 ms 643672 KB Output is correct
50 Correct 601 ms 698028 KB Output is correct
51 Correct 506 ms 680092 KB Output is correct
52 Correct 480 ms 688428 KB Output is correct
53 Correct 603 ms 698076 KB Output is correct
54 Correct 558 ms 697928 KB Output is correct
55 Correct 603 ms 698004 KB Output is correct
56 Correct 306 ms 643720 KB Output is correct
57 Correct 299 ms 643688 KB Output is correct
58 Correct 324 ms 643892 KB Output is correct
59 Correct 328 ms 643900 KB Output is correct
60 Correct 338 ms 644500 KB Output is correct
61 Correct 741 ms 697936 KB Output is correct
62 Correct 693 ms 696924 KB Output is correct
63 Correct 658 ms 683220 KB Output is correct
64 Correct 747 ms 698044 KB Output is correct
65 Correct 600 ms 698156 KB Output is correct
66 Correct 293 ms 643776 KB Output is correct
67 Correct 323 ms 643824 KB Output is correct
68 Correct 297 ms 643820 KB Output is correct
69 Correct 300 ms 643888 KB Output is correct
70 Correct 315 ms 645324 KB Output is correct
71 Correct 299 ms 644092 KB Output is correct
72 Correct 311 ms 644036 KB Output is correct
73 Correct 863 ms 694524 KB Output is correct
74 Correct 930 ms 693128 KB Output is correct
75 Correct 1033 ms 698132 KB Output is correct
76 Correct 1048 ms 697708 KB Output is correct
77 Correct 676 ms 696876 KB Output is correct
78 Correct 526 ms 676592 KB Output is correct
79 Correct 295 ms 644988 KB Output is correct
80 Correct 310 ms 645452 KB Output is correct
81 Correct 317 ms 645324 KB Output is correct
82 Correct 298 ms 645552 KB Output is correct
83 Correct 975 ms 697660 KB Output is correct
84 Correct 1103 ms 698756 KB Output is correct
85 Correct 1197 ms 699956 KB Output is correct
86 Correct 1228 ms 700620 KB Output is correct
87 Correct 807 ms 700036 KB Output is correct
88 Correct 1717 ms 727240 KB Output is correct
89 Correct 1510 ms 715480 KB Output is correct
90 Correct 1409 ms 719144 KB Output is correct
91 Correct 1493 ms 712108 KB Output is correct
92 Correct 1259 ms 704588 KB Output is correct
93 Correct 1717 ms 717088 KB Output is correct
94 Correct 1538 ms 710872 KB Output is correct
95 Correct 918 ms 708688 KB Output is correct
96 Correct 1734 ms 729668 KB Output is correct
97 Correct 606 ms 700232 KB Output is correct
98 Correct 638 ms 708616 KB Output is correct
99 Correct 693 ms 709620 KB Output is correct