Submission #688492

# Submission time Handle Problem Language Result Execution time Memory
688492 2023-01-27T14:30:32 Z dkblossom Team Contest (JOI22_team) C++14
100 / 100
87 ms 9648 KB
#include<bits/stdc++.h>
using namespace std;

#pragma gcc optimize('ofast','unroll-loops')

#define endl '\n'
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(a,b,c) for(int a=b;a<c;a++)

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll maxn = 150005;
const ll maxm = 200005;
const ll mod = 1000000007;

void solve(){
	int n;
	pii a[maxn], b[maxn], c[maxn];
	int tmpa[maxn], tmpb[maxn], tmpc[maxn];
	bitset<maxn> check;

	cin >> n;
	rep(i,0,n) cin >> a[i].ff >> b[i].ff >> c[i].ff, a[i].ss = b[i].ss = c[i].ss = i;
	rep(i,0,n) tmpa[i] = a[i].ff, tmpb[i] = b[i].ff, tmpc[i] = c[i].ff;

	sort(a,a+n), sort(b,b+n), sort(c,c+n);

	int at = n-1, bt = n-1, ct = n-1;

	while(1){
		if(at<0 || bt<0 || ct<0){
			cout << -1 << endl;
			return;
		}

		//cout << endl << at << ' ' << bt << ' ' << ct << ' ' << endl;

		if(tmpb[a[at].ss]==b[bt].ff || tmpc[a[at].ss]==c[ct].ff) check[a[at].ss] = 1;
		else if(tmpa[b[bt].ss]==a[at].ff || tmpc[b[bt].ss]==c[ct].ff) check[b[bt].ss] = 1;
		else if(tmpa[c[ct].ss]==a[at].ff || tmpb[c[ct].ss]==b[bt].ff) check[c[ct].ss] = 1;
		else{
			cout << a[at].ff+b[bt].ff+c[ct].ff << endl;
			return;
		}
		
		while(at>-1 && check[a[at].ss]) at--;
		while(bt>-1 && check[b[bt].ss]) bt--;
		while(ct>-1 && check[c[ct].ss]) ct--;
	}

}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("sol.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Compilation message

team.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    4 | #pragma gcc optimize('ofast','unroll-loops')
      |
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5620 KB Output is correct
4 Correct 4 ms 5588 KB Output is correct
5 Correct 3 ms 5616 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5620 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5620 KB Output is correct
11 Correct 3 ms 5588 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 3 ms 5624 KB Output is correct
14 Correct 3 ms 5588 KB Output is correct
15 Correct 3 ms 5588 KB Output is correct
16 Correct 3 ms 5588 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5588 KB Output is correct
20 Correct 3 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 3 ms 5588 KB Output is correct
23 Correct 3 ms 5716 KB Output is correct
24 Correct 3 ms 5588 KB Output is correct
25 Correct 3 ms 5616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5620 KB Output is correct
4 Correct 4 ms 5588 KB Output is correct
5 Correct 3 ms 5616 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5620 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5620 KB Output is correct
11 Correct 3 ms 5588 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 3 ms 5624 KB Output is correct
14 Correct 3 ms 5588 KB Output is correct
15 Correct 3 ms 5588 KB Output is correct
16 Correct 3 ms 5588 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5588 KB Output is correct
20 Correct 3 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 3 ms 5588 KB Output is correct
23 Correct 3 ms 5716 KB Output is correct
24 Correct 3 ms 5588 KB Output is correct
25 Correct 3 ms 5616 KB Output is correct
26 Correct 5 ms 5716 KB Output is correct
27 Correct 5 ms 5716 KB Output is correct
28 Correct 5 ms 5724 KB Output is correct
29 Correct 5 ms 5724 KB Output is correct
30 Correct 4 ms 5588 KB Output is correct
31 Correct 5 ms 5660 KB Output is correct
32 Correct 4 ms 5660 KB Output is correct
33 Correct 5 ms 5636 KB Output is correct
34 Correct 5 ms 5624 KB Output is correct
35 Correct 3 ms 5588 KB Output is correct
36 Correct 3 ms 5588 KB Output is correct
37 Correct 4 ms 5588 KB Output is correct
38 Correct 4 ms 5632 KB Output is correct
39 Correct 3 ms 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5588 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 3 ms 5588 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5616 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 59 ms 6476 KB Output is correct
12 Correct 41 ms 6180 KB Output is correct
13 Correct 43 ms 6332 KB Output is correct
14 Correct 62 ms 6476 KB Output is correct
15 Correct 57 ms 6604 KB Output is correct
16 Correct 32 ms 6364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5588 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 3 ms 5588 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5616 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 59 ms 6476 KB Output is correct
12 Correct 41 ms 6180 KB Output is correct
13 Correct 43 ms 6332 KB Output is correct
14 Correct 62 ms 6476 KB Output is correct
15 Correct 57 ms 6604 KB Output is correct
16 Correct 32 ms 6364 KB Output is correct
17 Correct 3 ms 5528 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5620 KB Output is correct
20 Correct 4 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 75 ms 6716 KB Output is correct
23 Correct 64 ms 6480 KB Output is correct
24 Correct 51 ms 6360 KB Output is correct
25 Correct 74 ms 6744 KB Output is correct
26 Correct 55 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5588 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 3 ms 5588 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5616 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 59 ms 6476 KB Output is correct
12 Correct 41 ms 6180 KB Output is correct
13 Correct 43 ms 6332 KB Output is correct
14 Correct 62 ms 6476 KB Output is correct
15 Correct 57 ms 6604 KB Output is correct
16 Correct 32 ms 6364 KB Output is correct
17 Correct 3 ms 5528 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5620 KB Output is correct
20 Correct 4 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 75 ms 6716 KB Output is correct
23 Correct 64 ms 6480 KB Output is correct
24 Correct 51 ms 6360 KB Output is correct
25 Correct 74 ms 6744 KB Output is correct
26 Correct 55 ms 6492 KB Output is correct
27 Correct 3 ms 5588 KB Output is correct
28 Correct 3 ms 5612 KB Output is correct
29 Correct 3 ms 5540 KB Output is correct
30 Correct 3 ms 5588 KB Output is correct
31 Correct 5 ms 5588 KB Output is correct
32 Correct 3 ms 5588 KB Output is correct
33 Correct 3 ms 5588 KB Output is correct
34 Correct 71 ms 7124 KB Output is correct
35 Correct 70 ms 7112 KB Output is correct
36 Correct 71 ms 7116 KB Output is correct
37 Correct 75 ms 7272 KB Output is correct
38 Correct 60 ms 7140 KB Output is correct
39 Correct 29 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5588 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 3 ms 5588 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5616 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 59 ms 6476 KB Output is correct
12 Correct 41 ms 6180 KB Output is correct
13 Correct 43 ms 6332 KB Output is correct
14 Correct 62 ms 6476 KB Output is correct
15 Correct 57 ms 6604 KB Output is correct
16 Correct 32 ms 6364 KB Output is correct
17 Correct 3 ms 5528 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5620 KB Output is correct
20 Correct 4 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 75 ms 6716 KB Output is correct
23 Correct 64 ms 6480 KB Output is correct
24 Correct 51 ms 6360 KB Output is correct
25 Correct 74 ms 6744 KB Output is correct
26 Correct 55 ms 6492 KB Output is correct
27 Correct 3 ms 5588 KB Output is correct
28 Correct 3 ms 5612 KB Output is correct
29 Correct 3 ms 5540 KB Output is correct
30 Correct 3 ms 5588 KB Output is correct
31 Correct 5 ms 5588 KB Output is correct
32 Correct 3 ms 5588 KB Output is correct
33 Correct 3 ms 5588 KB Output is correct
34 Correct 71 ms 7124 KB Output is correct
35 Correct 70 ms 7112 KB Output is correct
36 Correct 71 ms 7116 KB Output is correct
37 Correct 75 ms 7272 KB Output is correct
38 Correct 60 ms 7140 KB Output is correct
39 Correct 29 ms 6492 KB Output is correct
40 Correct 4 ms 5588 KB Output is correct
41 Correct 4 ms 5660 KB Output is correct
42 Correct 4 ms 5588 KB Output is correct
43 Correct 6 ms 5588 KB Output is correct
44 Correct 73 ms 7628 KB Output is correct
45 Correct 75 ms 7636 KB Output is correct
46 Correct 74 ms 7628 KB Output is correct
47 Correct 76 ms 7644 KB Output is correct
48 Correct 66 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5588 KB Output is correct
2 Correct 3 ms 5620 KB Output is correct
3 Correct 4 ms 5620 KB Output is correct
4 Correct 4 ms 5588 KB Output is correct
5 Correct 3 ms 5616 KB Output is correct
6 Correct 3 ms 5616 KB Output is correct
7 Correct 3 ms 5620 KB Output is correct
8 Correct 3 ms 5588 KB Output is correct
9 Correct 3 ms 5588 KB Output is correct
10 Correct 3 ms 5620 KB Output is correct
11 Correct 3 ms 5588 KB Output is correct
12 Correct 3 ms 5588 KB Output is correct
13 Correct 3 ms 5624 KB Output is correct
14 Correct 3 ms 5588 KB Output is correct
15 Correct 3 ms 5588 KB Output is correct
16 Correct 3 ms 5588 KB Output is correct
17 Correct 3 ms 5588 KB Output is correct
18 Correct 3 ms 5588 KB Output is correct
19 Correct 3 ms 5588 KB Output is correct
20 Correct 3 ms 5588 KB Output is correct
21 Correct 3 ms 5588 KB Output is correct
22 Correct 3 ms 5588 KB Output is correct
23 Correct 3 ms 5716 KB Output is correct
24 Correct 3 ms 5588 KB Output is correct
25 Correct 3 ms 5616 KB Output is correct
26 Correct 5 ms 5716 KB Output is correct
27 Correct 5 ms 5716 KB Output is correct
28 Correct 5 ms 5724 KB Output is correct
29 Correct 5 ms 5724 KB Output is correct
30 Correct 4 ms 5588 KB Output is correct
31 Correct 5 ms 5660 KB Output is correct
32 Correct 4 ms 5660 KB Output is correct
33 Correct 5 ms 5636 KB Output is correct
34 Correct 5 ms 5624 KB Output is correct
35 Correct 3 ms 5588 KB Output is correct
36 Correct 3 ms 5588 KB Output is correct
37 Correct 4 ms 5588 KB Output is correct
38 Correct 4 ms 5632 KB Output is correct
39 Correct 3 ms 5632 KB Output is correct
40 Correct 2 ms 5588 KB Output is correct
41 Correct 3 ms 5620 KB Output is correct
42 Correct 4 ms 5588 KB Output is correct
43 Correct 3 ms 5588 KB Output is correct
44 Correct 3 ms 5588 KB Output is correct
45 Correct 3 ms 5616 KB Output is correct
46 Correct 3 ms 5616 KB Output is correct
47 Correct 3 ms 5588 KB Output is correct
48 Correct 3 ms 5588 KB Output is correct
49 Correct 3 ms 5588 KB Output is correct
50 Correct 59 ms 6476 KB Output is correct
51 Correct 41 ms 6180 KB Output is correct
52 Correct 43 ms 6332 KB Output is correct
53 Correct 62 ms 6476 KB Output is correct
54 Correct 57 ms 6604 KB Output is correct
55 Correct 32 ms 6364 KB Output is correct
56 Correct 3 ms 5528 KB Output is correct
57 Correct 3 ms 5588 KB Output is correct
58 Correct 3 ms 5620 KB Output is correct
59 Correct 4 ms 5588 KB Output is correct
60 Correct 3 ms 5588 KB Output is correct
61 Correct 75 ms 6716 KB Output is correct
62 Correct 64 ms 6480 KB Output is correct
63 Correct 51 ms 6360 KB Output is correct
64 Correct 74 ms 6744 KB Output is correct
65 Correct 55 ms 6492 KB Output is correct
66 Correct 3 ms 5588 KB Output is correct
67 Correct 3 ms 5612 KB Output is correct
68 Correct 3 ms 5540 KB Output is correct
69 Correct 3 ms 5588 KB Output is correct
70 Correct 5 ms 5588 KB Output is correct
71 Correct 3 ms 5588 KB Output is correct
72 Correct 3 ms 5588 KB Output is correct
73 Correct 71 ms 7124 KB Output is correct
74 Correct 70 ms 7112 KB Output is correct
75 Correct 71 ms 7116 KB Output is correct
76 Correct 75 ms 7272 KB Output is correct
77 Correct 60 ms 7140 KB Output is correct
78 Correct 29 ms 6492 KB Output is correct
79 Correct 4 ms 5588 KB Output is correct
80 Correct 4 ms 5660 KB Output is correct
81 Correct 4 ms 5588 KB Output is correct
82 Correct 6 ms 5588 KB Output is correct
83 Correct 73 ms 7628 KB Output is correct
84 Correct 75 ms 7636 KB Output is correct
85 Correct 74 ms 7628 KB Output is correct
86 Correct 76 ms 7644 KB Output is correct
87 Correct 66 ms 7512 KB Output is correct
88 Correct 75 ms 9504 KB Output is correct
89 Correct 82 ms 9424 KB Output is correct
90 Correct 79 ms 9504 KB Output is correct
91 Correct 87 ms 9560 KB Output is correct
92 Correct 79 ms 8012 KB Output is correct
93 Correct 77 ms 8268 KB Output is correct
94 Correct 81 ms 8212 KB Output is correct
95 Correct 72 ms 9300 KB Output is correct
96 Correct 78 ms 9552 KB Output is correct
97 Correct 48 ms 9648 KB Output is correct
98 Correct 42 ms 8148 KB Output is correct
99 Correct 67 ms 8136 KB Output is correct