Submission #892187

# Submission time Handle Problem Language Result Execution time Memory
892187 2023-12-25T03:46:29 Z vjudge1 Team Contest (JOI22_team) C++17
100 / 100
466 ms 36436 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define mpa make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define bc back()
#define ar array
#define vll vector<ll> 
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;*/
template <class _T>
bool chmin(_T &x, const _T &y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=2e18+7;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;

void solve(){
	ll i;
	ll n,k;
	cin>>n;
	ll xx[n],yy[n],zz[n];
	set<pair<ll,ll>> x,y,z;
	for(i=0;i<n;i++){
		ll a,b,c;
		cin>>a>>b>>c;
		xx[i]=a;
		yy[i]=b;
		zz[i]=c;
		x.ins({a,i});
		y.ins({b,i});
		z.ins({c,i});
	}
	for(i=0;i<n;i++){
		vector<ll> v;
		v.pb(x.rbegin()->sc);
		v.pb(y.rbegin()->sc);
		v.pb(z.rbegin()->sc);
		if(yy[v[1]]==yy[v[0]] || zz[v[0]]==zz[v[2]]){
			x.erase(x.find({xx[v[0]],v[0]}));
			y.erase(y.find({yy[v[0]],v[0]}));
			z.erase(z.find({zz[v[0]],v[0]}));
		}else if(xx[v[1]]==xx[v[0]] || zz[v[1]]==zz[v[2]]){
			x.erase(x.find({xx[v[1]],v[1]}));
			y.erase(y.find({yy[v[1]],v[1]}));
			z.erase(z.find({zz[v[1]],v[1]}));
		}else if(xx[v[2]]==xx[v[0]] || yy[v[1]]==yy[v[2]]){
			x.erase(x.find({xx[v[2]],v[2]}));
			y.erase(y.find({yy[v[2]],v[2]}));
			z.erase(z.find({zz[v[2]],v[2]}));
		}else{
			cout<<xx[v[0]]+yy[v[1]]+zz[v[2]]<<endl;
			return;
		}
	}
	cout<<-1<<endl;
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*
1
7
1 2
2 3
3 4
4 5
3 6
6 7
2
4 1
5 7






*/

Compilation message

team.cpp: In function 'void solve()':
team.cpp:56:7: warning: unused variable 'k' [-Wunused-variable]
   56 |  ll n,k;
      |       ^
team.cpp: In function 'void fre(std::string)':
team.cpp:43:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:43:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 4 ms 1228 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 5 ms 1372 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 3 ms 1316 KB Output is correct
32 Correct 6 ms 1116 KB Output is correct
33 Correct 6 ms 1120 KB Output is correct
34 Correct 4 ms 1372 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 3 ms 1312 KB Output is correct
39 Correct 2 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 608 KB Output is correct
11 Correct 140 ms 31968 KB Output is correct
12 Correct 138 ms 21328 KB Output is correct
13 Correct 104 ms 26460 KB Output is correct
14 Correct 195 ms 32232 KB Output is correct
15 Correct 138 ms 32084 KB Output is correct
16 Correct 141 ms 31968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 608 KB Output is correct
11 Correct 140 ms 31968 KB Output is correct
12 Correct 138 ms 21328 KB Output is correct
13 Correct 104 ms 26460 KB Output is correct
14 Correct 195 ms 32232 KB Output is correct
15 Correct 138 ms 32084 KB Output is correct
16 Correct 141 ms 31968 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 864 KB Output is correct
22 Correct 189 ms 32796 KB Output is correct
23 Correct 177 ms 32072 KB Output is correct
24 Correct 171 ms 24372 KB Output is correct
25 Correct 307 ms 33204 KB Output is correct
26 Correct 150 ms 33104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 608 KB Output is correct
11 Correct 140 ms 31968 KB Output is correct
12 Correct 138 ms 21328 KB Output is correct
13 Correct 104 ms 26460 KB Output is correct
14 Correct 195 ms 32232 KB Output is correct
15 Correct 138 ms 32084 KB Output is correct
16 Correct 141 ms 31968 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 864 KB Output is correct
22 Correct 189 ms 32796 KB Output is correct
23 Correct 177 ms 32072 KB Output is correct
24 Correct 171 ms 24372 KB Output is correct
25 Correct 307 ms 33204 KB Output is correct
26 Correct 150 ms 33104 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 7 ms 1352 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 243 ms 32084 KB Output is correct
35 Correct 320 ms 30460 KB Output is correct
36 Correct 321 ms 33656 KB Output is correct
37 Correct 379 ms 33504 KB Output is correct
38 Correct 208 ms 32940 KB Output is correct
39 Correct 95 ms 20416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 608 KB Output is correct
11 Correct 140 ms 31968 KB Output is correct
12 Correct 138 ms 21328 KB Output is correct
13 Correct 104 ms 26460 KB Output is correct
14 Correct 195 ms 32232 KB Output is correct
15 Correct 138 ms 32084 KB Output is correct
16 Correct 141 ms 31968 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 864 KB Output is correct
22 Correct 189 ms 32796 KB Output is correct
23 Correct 177 ms 32072 KB Output is correct
24 Correct 171 ms 24372 KB Output is correct
25 Correct 307 ms 33204 KB Output is correct
26 Correct 150 ms 33104 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 7 ms 1352 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 243 ms 32084 KB Output is correct
35 Correct 320 ms 30460 KB Output is correct
36 Correct 321 ms 33656 KB Output is correct
37 Correct 379 ms 33504 KB Output is correct
38 Correct 208 ms 32940 KB Output is correct
39 Correct 95 ms 20416 KB Output is correct
40 Correct 3 ms 860 KB Output is correct
41 Correct 3 ms 1112 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 3 ms 1116 KB Output is correct
44 Correct 358 ms 34120 KB Output is correct
45 Correct 466 ms 34248 KB Output is correct
46 Correct 366 ms 34048 KB Output is correct
47 Correct 444 ms 34180 KB Output is correct
48 Correct 220 ms 34076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 4 ms 1228 KB Output is correct
28 Correct 4 ms 1372 KB Output is correct
29 Correct 5 ms 1372 KB Output is correct
30 Correct 3 ms 856 KB Output is correct
31 Correct 3 ms 1316 KB Output is correct
32 Correct 6 ms 1116 KB Output is correct
33 Correct 6 ms 1120 KB Output is correct
34 Correct 4 ms 1372 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 3 ms 1312 KB Output is correct
39 Correct 2 ms 864 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 392 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 600 KB Output is correct
49 Correct 0 ms 608 KB Output is correct
50 Correct 140 ms 31968 KB Output is correct
51 Correct 138 ms 21328 KB Output is correct
52 Correct 104 ms 26460 KB Output is correct
53 Correct 195 ms 32232 KB Output is correct
54 Correct 138 ms 32084 KB Output is correct
55 Correct 141 ms 31968 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 2 ms 864 KB Output is correct
61 Correct 189 ms 32796 KB Output is correct
62 Correct 177 ms 32072 KB Output is correct
63 Correct 171 ms 24372 KB Output is correct
64 Correct 307 ms 33204 KB Output is correct
65 Correct 150 ms 33104 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 7 ms 1352 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 464 KB Output is correct
73 Correct 243 ms 32084 KB Output is correct
74 Correct 320 ms 30460 KB Output is correct
75 Correct 321 ms 33656 KB Output is correct
76 Correct 379 ms 33504 KB Output is correct
77 Correct 208 ms 32940 KB Output is correct
78 Correct 95 ms 20416 KB Output is correct
79 Correct 3 ms 860 KB Output is correct
80 Correct 3 ms 1112 KB Output is correct
81 Correct 3 ms 1116 KB Output is correct
82 Correct 3 ms 1116 KB Output is correct
83 Correct 358 ms 34120 KB Output is correct
84 Correct 466 ms 34248 KB Output is correct
85 Correct 366 ms 34048 KB Output is correct
86 Correct 444 ms 34180 KB Output is correct
87 Correct 220 ms 34076 KB Output is correct
88 Correct 319 ms 36064 KB Output is correct
89 Correct 319 ms 36040 KB Output is correct
90 Correct 325 ms 35916 KB Output is correct
91 Correct 377 ms 35784 KB Output is correct
92 Correct 322 ms 34644 KB Output is correct
93 Correct 370 ms 34904 KB Output is correct
94 Correct 379 ms 34740 KB Output is correct
95 Correct 222 ms 35672 KB Output is correct
96 Correct 179 ms 35852 KB Output is correct
97 Correct 166 ms 36436 KB Output is correct
98 Correct 154 ms 34600 KB Output is correct
99 Correct 165 ms 34644 KB Output is correct