Submission #986731

# Submission time Handle Problem Language Result Execution time Memory
986731 2024-05-21T06:17:43 Z AlperenT_ Team Contest (JOI22_team) C++17
100 / 100
268 ms 73604 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <ll,ll>
#define PII pair<pii , pii>
#define ld long double
#define ll long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i , a , b) for(int i=a;i >= b;i--)
using namespace std ;
const int maxn = 6e5 + 10  , N = 1e5 +1 , lg = 20 , maxq = 202   , inf = 1e9  , maxk = 2022  , mod =998244353;
int a[3][maxn] , id[3] , mark[maxn]; 
vector <int> vec[3][maxn] ;
set <int> s[3] ;

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);   
    int n ;cin >> n ;
    vector <int> cm[4] ;
    rep(i ,1 ,n){
        rep(j ,0 , 2){
            cin >> a[j][i] ;
            cm[j].pb(a[j][i]);
        }
    }
    rep(i , 0 ,2){
        sort(all(cm[i])) ;
    }
    rep(i , 0 , 2)id[i] =sz(cm[i])-1 ;
    rep(i , 1, n){
        rep(j , 0 , 2){
            a[j][i] = lower_bound(all(cm[j]) , a[j][i])-cm[j].begin();
            vec[j][a[j][i]].pb(i) ;
        }
    }
    while(1){
        bool ok =0 ;
        rep(i , 0 , 2)if(sz(s[i]) ==0 )ok=1;
        if(ok == 1){
            ok =0 ; 
            rep(i , 0,2){
                if(sz(s[i])!=0)continue ;
                if(id[i] == -1){
                    ok = 1 ;
                    break ;
                }
                for(int x : vec[i][id[i]]){
                    if(mark[x] == 1)continue;
                    s[i].insert(x);
                }
                id[i]--;
            }
            if(ok == 1)break ;
            continue ;
        }
        while(1){
            ok =0 ;
            rep(i , 0 ,2){
                if(sz(s[i]) == 0)ok = 1; 
            }
            if(ok == 1)break ;
            int b[3] ;
            rep(i , 0,2){
                b[i] = (*s[i].begin()) ;
            }
            int k = -1 ;
            rep(i , 0 ,2){
                rep(j , 0, 2){
                    if(i == j)continue ;
                    if(s[j].find(b[i])!=s[j].end()){
                        k = i ;
                    }
                }
            }
            if(k == -1){
                int ans =0 ;
                rep(i , 0 ,2){
                    ans += cm[i][id[i]+1] ;
                }
                cout << ans << "\n";
                exit(0) ;
            }
            mark[b[k]] = 1; 
            rep(i , 0, 2){
                s[i].erase(b[k]);
            }
        }
    }
    cout << -1 << "\n" ;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 24 ms 42560 KB Output is correct
3 Correct 22 ms 42584 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 22 ms 42724 KB Output is correct
6 Correct 21 ms 42584 KB Output is correct
7 Correct 22 ms 42588 KB Output is correct
8 Correct 22 ms 42588 KB Output is correct
9 Correct 22 ms 42728 KB Output is correct
10 Correct 22 ms 42588 KB Output is correct
11 Correct 26 ms 42512 KB Output is correct
12 Correct 22 ms 42648 KB Output is correct
13 Correct 25 ms 42588 KB Output is correct
14 Correct 22 ms 42576 KB Output is correct
15 Correct 22 ms 42584 KB Output is correct
16 Correct 22 ms 42588 KB Output is correct
17 Correct 22 ms 42588 KB Output is correct
18 Correct 26 ms 42744 KB Output is correct
19 Correct 22 ms 42732 KB Output is correct
20 Correct 25 ms 42584 KB Output is correct
21 Correct 22 ms 42764 KB Output is correct
22 Correct 22 ms 42584 KB Output is correct
23 Correct 23 ms 42588 KB Output is correct
24 Correct 22 ms 43040 KB Output is correct
25 Correct 22 ms 42552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 24 ms 42560 KB Output is correct
3 Correct 22 ms 42584 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 22 ms 42724 KB Output is correct
6 Correct 21 ms 42584 KB Output is correct
7 Correct 22 ms 42588 KB Output is correct
8 Correct 22 ms 42588 KB Output is correct
9 Correct 22 ms 42728 KB Output is correct
10 Correct 22 ms 42588 KB Output is correct
11 Correct 26 ms 42512 KB Output is correct
12 Correct 22 ms 42648 KB Output is correct
13 Correct 25 ms 42588 KB Output is correct
14 Correct 22 ms 42576 KB Output is correct
15 Correct 22 ms 42584 KB Output is correct
16 Correct 22 ms 42588 KB Output is correct
17 Correct 22 ms 42588 KB Output is correct
18 Correct 26 ms 42744 KB Output is correct
19 Correct 22 ms 42732 KB Output is correct
20 Correct 25 ms 42584 KB Output is correct
21 Correct 22 ms 42764 KB Output is correct
22 Correct 22 ms 42584 KB Output is correct
23 Correct 23 ms 42588 KB Output is correct
24 Correct 22 ms 43040 KB Output is correct
25 Correct 22 ms 42552 KB Output is correct
26 Correct 25 ms 43100 KB Output is correct
27 Correct 26 ms 43352 KB Output is correct
28 Correct 26 ms 43100 KB Output is correct
29 Correct 27 ms 43092 KB Output is correct
30 Correct 24 ms 42844 KB Output is correct
31 Correct 25 ms 42844 KB Output is correct
32 Correct 25 ms 43096 KB Output is correct
33 Correct 25 ms 43356 KB Output is correct
34 Correct 25 ms 43352 KB Output is correct
35 Correct 22 ms 42584 KB Output is correct
36 Correct 25 ms 42588 KB Output is correct
37 Correct 23 ms 43064 KB Output is correct
38 Correct 25 ms 42844 KB Output is correct
39 Correct 23 ms 42840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42588 KB Output is correct
3 Correct 22 ms 42588 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 25 ms 42736 KB Output is correct
6 Correct 23 ms 42588 KB Output is correct
7 Correct 21 ms 42524 KB Output is correct
8 Correct 21 ms 42588 KB Output is correct
9 Correct 26 ms 42588 KB Output is correct
10 Correct 21 ms 42588 KB Output is correct
11 Correct 78 ms 53172 KB Output is correct
12 Correct 91 ms 50520 KB Output is correct
13 Correct 56 ms 48836 KB Output is correct
14 Correct 153 ms 55992 KB Output is correct
15 Correct 173 ms 65484 KB Output is correct
16 Correct 181 ms 70500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42588 KB Output is correct
3 Correct 22 ms 42588 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 25 ms 42736 KB Output is correct
6 Correct 23 ms 42588 KB Output is correct
7 Correct 21 ms 42524 KB Output is correct
8 Correct 21 ms 42588 KB Output is correct
9 Correct 26 ms 42588 KB Output is correct
10 Correct 21 ms 42588 KB Output is correct
11 Correct 78 ms 53172 KB Output is correct
12 Correct 91 ms 50520 KB Output is correct
13 Correct 56 ms 48836 KB Output is correct
14 Correct 153 ms 55992 KB Output is correct
15 Correct 173 ms 65484 KB Output is correct
16 Correct 181 ms 70500 KB Output is correct
17 Correct 21 ms 42588 KB Output is correct
18 Correct 24 ms 42676 KB Output is correct
19 Correct 21 ms 42588 KB Output is correct
20 Correct 22 ms 42588 KB Output is correct
21 Correct 22 ms 42984 KB Output is correct
22 Correct 89 ms 50204 KB Output is correct
23 Correct 89 ms 49848 KB Output is correct
24 Correct 106 ms 48952 KB Output is correct
25 Correct 168 ms 52676 KB Output is correct
26 Correct 217 ms 65568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42588 KB Output is correct
3 Correct 22 ms 42588 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 25 ms 42736 KB Output is correct
6 Correct 23 ms 42588 KB Output is correct
7 Correct 21 ms 42524 KB Output is correct
8 Correct 21 ms 42588 KB Output is correct
9 Correct 26 ms 42588 KB Output is correct
10 Correct 21 ms 42588 KB Output is correct
11 Correct 78 ms 53172 KB Output is correct
12 Correct 91 ms 50520 KB Output is correct
13 Correct 56 ms 48836 KB Output is correct
14 Correct 153 ms 55992 KB Output is correct
15 Correct 173 ms 65484 KB Output is correct
16 Correct 181 ms 70500 KB Output is correct
17 Correct 21 ms 42588 KB Output is correct
18 Correct 24 ms 42676 KB Output is correct
19 Correct 21 ms 42588 KB Output is correct
20 Correct 22 ms 42588 KB Output is correct
21 Correct 22 ms 42984 KB Output is correct
22 Correct 89 ms 50204 KB Output is correct
23 Correct 89 ms 49848 KB Output is correct
24 Correct 106 ms 48952 KB Output is correct
25 Correct 168 ms 52676 KB Output is correct
26 Correct 217 ms 65568 KB Output is correct
27 Correct 21 ms 42588 KB Output is correct
28 Correct 21 ms 42588 KB Output is correct
29 Correct 23 ms 42588 KB Output is correct
30 Correct 22 ms 42760 KB Output is correct
31 Correct 31 ms 42932 KB Output is correct
32 Correct 21 ms 42588 KB Output is correct
33 Correct 22 ms 42588 KB Output is correct
34 Correct 124 ms 49592 KB Output is correct
35 Correct 133 ms 50872 KB Output is correct
36 Correct 173 ms 51204 KB Output is correct
37 Correct 188 ms 51136 KB Output is correct
38 Correct 195 ms 65844 KB Output is correct
39 Correct 95 ms 51908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 21 ms 42588 KB Output is correct
3 Correct 22 ms 42588 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 25 ms 42736 KB Output is correct
6 Correct 23 ms 42588 KB Output is correct
7 Correct 21 ms 42524 KB Output is correct
8 Correct 21 ms 42588 KB Output is correct
9 Correct 26 ms 42588 KB Output is correct
10 Correct 21 ms 42588 KB Output is correct
11 Correct 78 ms 53172 KB Output is correct
12 Correct 91 ms 50520 KB Output is correct
13 Correct 56 ms 48836 KB Output is correct
14 Correct 153 ms 55992 KB Output is correct
15 Correct 173 ms 65484 KB Output is correct
16 Correct 181 ms 70500 KB Output is correct
17 Correct 21 ms 42588 KB Output is correct
18 Correct 24 ms 42676 KB Output is correct
19 Correct 21 ms 42588 KB Output is correct
20 Correct 22 ms 42588 KB Output is correct
21 Correct 22 ms 42984 KB Output is correct
22 Correct 89 ms 50204 KB Output is correct
23 Correct 89 ms 49848 KB Output is correct
24 Correct 106 ms 48952 KB Output is correct
25 Correct 168 ms 52676 KB Output is correct
26 Correct 217 ms 65568 KB Output is correct
27 Correct 21 ms 42588 KB Output is correct
28 Correct 21 ms 42588 KB Output is correct
29 Correct 23 ms 42588 KB Output is correct
30 Correct 22 ms 42760 KB Output is correct
31 Correct 31 ms 42932 KB Output is correct
32 Correct 21 ms 42588 KB Output is correct
33 Correct 22 ms 42588 KB Output is correct
34 Correct 124 ms 49592 KB Output is correct
35 Correct 133 ms 50872 KB Output is correct
36 Correct 173 ms 51204 KB Output is correct
37 Correct 188 ms 51136 KB Output is correct
38 Correct 195 ms 65844 KB Output is correct
39 Correct 95 ms 51908 KB Output is correct
40 Correct 27 ms 42844 KB Output is correct
41 Correct 25 ms 42844 KB Output is correct
42 Correct 24 ms 42844 KB Output is correct
43 Correct 25 ms 42844 KB Output is correct
44 Correct 148 ms 51568 KB Output is correct
45 Correct 196 ms 51640 KB Output is correct
46 Correct 183 ms 51832 KB Output is correct
47 Correct 202 ms 51888 KB Output is correct
48 Correct 208 ms 66744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 42588 KB Output is correct
2 Correct 24 ms 42560 KB Output is correct
3 Correct 22 ms 42584 KB Output is correct
4 Correct 22 ms 42588 KB Output is correct
5 Correct 22 ms 42724 KB Output is correct
6 Correct 21 ms 42584 KB Output is correct
7 Correct 22 ms 42588 KB Output is correct
8 Correct 22 ms 42588 KB Output is correct
9 Correct 22 ms 42728 KB Output is correct
10 Correct 22 ms 42588 KB Output is correct
11 Correct 26 ms 42512 KB Output is correct
12 Correct 22 ms 42648 KB Output is correct
13 Correct 25 ms 42588 KB Output is correct
14 Correct 22 ms 42576 KB Output is correct
15 Correct 22 ms 42584 KB Output is correct
16 Correct 22 ms 42588 KB Output is correct
17 Correct 22 ms 42588 KB Output is correct
18 Correct 26 ms 42744 KB Output is correct
19 Correct 22 ms 42732 KB Output is correct
20 Correct 25 ms 42584 KB Output is correct
21 Correct 22 ms 42764 KB Output is correct
22 Correct 22 ms 42584 KB Output is correct
23 Correct 23 ms 42588 KB Output is correct
24 Correct 22 ms 43040 KB Output is correct
25 Correct 22 ms 42552 KB Output is correct
26 Correct 25 ms 43100 KB Output is correct
27 Correct 26 ms 43352 KB Output is correct
28 Correct 26 ms 43100 KB Output is correct
29 Correct 27 ms 43092 KB Output is correct
30 Correct 24 ms 42844 KB Output is correct
31 Correct 25 ms 42844 KB Output is correct
32 Correct 25 ms 43096 KB Output is correct
33 Correct 25 ms 43356 KB Output is correct
34 Correct 25 ms 43352 KB Output is correct
35 Correct 22 ms 42584 KB Output is correct
36 Correct 25 ms 42588 KB Output is correct
37 Correct 23 ms 43064 KB Output is correct
38 Correct 25 ms 42844 KB Output is correct
39 Correct 23 ms 42840 KB Output is correct
40 Correct 21 ms 42588 KB Output is correct
41 Correct 21 ms 42588 KB Output is correct
42 Correct 22 ms 42588 KB Output is correct
43 Correct 22 ms 42588 KB Output is correct
44 Correct 25 ms 42736 KB Output is correct
45 Correct 23 ms 42588 KB Output is correct
46 Correct 21 ms 42524 KB Output is correct
47 Correct 21 ms 42588 KB Output is correct
48 Correct 26 ms 42588 KB Output is correct
49 Correct 21 ms 42588 KB Output is correct
50 Correct 78 ms 53172 KB Output is correct
51 Correct 91 ms 50520 KB Output is correct
52 Correct 56 ms 48836 KB Output is correct
53 Correct 153 ms 55992 KB Output is correct
54 Correct 173 ms 65484 KB Output is correct
55 Correct 181 ms 70500 KB Output is correct
56 Correct 21 ms 42588 KB Output is correct
57 Correct 24 ms 42676 KB Output is correct
58 Correct 21 ms 42588 KB Output is correct
59 Correct 22 ms 42588 KB Output is correct
60 Correct 22 ms 42984 KB Output is correct
61 Correct 89 ms 50204 KB Output is correct
62 Correct 89 ms 49848 KB Output is correct
63 Correct 106 ms 48952 KB Output is correct
64 Correct 168 ms 52676 KB Output is correct
65 Correct 217 ms 65568 KB Output is correct
66 Correct 21 ms 42588 KB Output is correct
67 Correct 21 ms 42588 KB Output is correct
68 Correct 23 ms 42588 KB Output is correct
69 Correct 22 ms 42760 KB Output is correct
70 Correct 31 ms 42932 KB Output is correct
71 Correct 21 ms 42588 KB Output is correct
72 Correct 22 ms 42588 KB Output is correct
73 Correct 124 ms 49592 KB Output is correct
74 Correct 133 ms 50872 KB Output is correct
75 Correct 173 ms 51204 KB Output is correct
76 Correct 188 ms 51136 KB Output is correct
77 Correct 195 ms 65844 KB Output is correct
78 Correct 95 ms 51908 KB Output is correct
79 Correct 27 ms 42844 KB Output is correct
80 Correct 25 ms 42844 KB Output is correct
81 Correct 24 ms 42844 KB Output is correct
82 Correct 25 ms 42844 KB Output is correct
83 Correct 148 ms 51568 KB Output is correct
84 Correct 196 ms 51640 KB Output is correct
85 Correct 183 ms 51832 KB Output is correct
86 Correct 202 ms 51888 KB Output is correct
87 Correct 208 ms 66744 KB Output is correct
88 Correct 232 ms 64164 KB Output is correct
89 Correct 268 ms 58548 KB Output is correct
90 Correct 214 ms 59480 KB Output is correct
91 Correct 241 ms 57276 KB Output is correct
92 Correct 231 ms 53488 KB Output is correct
93 Correct 246 ms 57756 KB Output is correct
94 Correct 245 ms 55172 KB Output is correct
95 Correct 240 ms 71296 KB Output is correct
96 Correct 250 ms 64668 KB Output is correct
97 Correct 194 ms 73604 KB Output is correct
98 Correct 92 ms 54192 KB Output is correct
99 Correct 149 ms 54540 KB Output is correct