Submission #669066

# Submission time Handle Problem Language Result Execution time Memory
669066 2022-12-05T13:45:27 Z ktkerem Homework (CEOI22_homework) C++17
53 / 100
155 ms 184036 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
//typedef vector<std::vector<ll>> vv; 
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define vv(x) std::vector<std::vector<x>>
#define all(a) a.begin() , a.end()
const ll limit = 1e15+7; 
const ll ous = 1e6 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n;std::vector<ll> adj[ous];ll x = 0;
ll ff = 0;std::string s;
ll typ[ous];
void buildadj(ll prv){
    ll crt = ff++;
    if(s[x++] == '?'){
        n++;
        typ[crt] = 0;
        if(prv < 0){
            return;
        }
        adj[crt].pb(prv);
        adj[prv].pb(crt);
        return;
    }
    char c = s[x];
    x+=3;
    buildadj(crt);
    x++;
    buildadj(crt);
    x++;
    if(c == 'i'){
        typ[crt] = 1;
    }
    else{
        typ[crt] = 2;
    }
    if(prv >= 0){
        adj[prv].pb(crt);
        adj[crt].pb(prv);
    }
} 
llll dfs(ll crt , ll prv = -1){
    if(typ[crt] == 0){
        return{1 , n};
    }
    else if(typ[crt] == 1){
        std::vector<llll> v;
        for(auto j:adj[crt]){
            if(j != prv){
                v.pb(dfs(j , crt));
            }
        }
        assert(v.size() >= 2);
        //std::cout << v.size() << std::endl;
        return {std::min(v[0].fi , v[1].fi) , v[0].sec + v[1].sec - n - 1};
    }
    else{
        std::vector<llll> v;
        for(auto j:adj[crt]){
            if(j != prv){
                v.pb(dfs(j , crt));
            }
        }
        assert(v.size() >= 2);
        //std::cout << v.size() << std::endl;
        return {v[0].fi + v[1].fi , std::max(v[0].sec , v[1].sec)};
    }
    return {0 , 0};
}
void solve(){
    std::cin >> s;
    buildadj(-1);
    llll ans = dfs(0);
    std::cout << ans.sec - ans.fi + 1 << "\n";
    return;
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
    //std::cin >> t;
    ll o = 1;
    while(t--){ 
        solve();        
    }
    return 0;
}/**/

Compilation message

Main.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
Main.cpp: In function 'int main()':
Main.cpp:97:8: warning: unused variable 'o' [-Wunused-variable]
   97 |     ll o = 1;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 23764 KB Output is correct
3 Correct 13 ms 23696 KB Output is correct
4 Correct 14 ms 23716 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 14 ms 23824 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23708 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 16 ms 23708 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 13 ms 23816 KB Output is correct
18 Correct 13 ms 23788 KB Output is correct
19 Correct 14 ms 23688 KB Output is correct
20 Correct 14 ms 23724 KB Output is correct
21 Correct 14 ms 23720 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 13 ms 23788 KB Output is correct
24 Correct 13 ms 23804 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23812 KB Output is correct
27 Correct 13 ms 23808 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 23764 KB Output is correct
3 Correct 13 ms 23696 KB Output is correct
4 Correct 14 ms 23716 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 14 ms 23824 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23708 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 16 ms 23708 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 13 ms 23816 KB Output is correct
18 Correct 13 ms 23788 KB Output is correct
19 Correct 14 ms 23688 KB Output is correct
20 Correct 14 ms 23724 KB Output is correct
21 Correct 14 ms 23720 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 13 ms 23788 KB Output is correct
24 Correct 13 ms 23804 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23812 KB Output is correct
27 Correct 13 ms 23808 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 13 ms 23696 KB Output is correct
30 Correct 14 ms 23764 KB Output is correct
31 Correct 13 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 14 ms 23800 KB Output is correct
34 Correct 16 ms 23820 KB Output is correct
35 Correct 12 ms 23784 KB Output is correct
36 Correct 13 ms 23752 KB Output is correct
37 Correct 13 ms 23820 KB Output is correct
38 Correct 14 ms 23764 KB Output is correct
39 Correct 15 ms 23792 KB Output is correct
40 Correct 15 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 13 ms 23816 KB Output is correct
43 Correct 14 ms 23760 KB Output is correct
44 Correct 13 ms 23764 KB Output is correct
45 Correct 13 ms 23720 KB Output is correct
46 Correct 13 ms 23764 KB Output is correct
47 Correct 13 ms 23772 KB Output is correct
48 Correct 14 ms 23748 KB Output is correct
49 Correct 14 ms 23764 KB Output is correct
50 Correct 13 ms 23764 KB Output is correct
51 Correct 16 ms 23764 KB Output is correct
52 Correct 18 ms 23764 KB Output is correct
53 Correct 13 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 13 ms 23732 KB Output is correct
56 Correct 13 ms 23812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 155 ms 184036 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 23764 KB Output is correct
3 Correct 13 ms 23696 KB Output is correct
4 Correct 14 ms 23716 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 14 ms 23824 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23708 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 16 ms 23708 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 13 ms 23816 KB Output is correct
18 Correct 13 ms 23788 KB Output is correct
19 Correct 14 ms 23688 KB Output is correct
20 Correct 14 ms 23724 KB Output is correct
21 Correct 14 ms 23720 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 13 ms 23788 KB Output is correct
24 Correct 13 ms 23804 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23812 KB Output is correct
27 Correct 13 ms 23808 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 13 ms 23696 KB Output is correct
30 Correct 14 ms 23764 KB Output is correct
31 Correct 13 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 14 ms 23800 KB Output is correct
34 Correct 16 ms 23820 KB Output is correct
35 Correct 12 ms 23784 KB Output is correct
36 Correct 13 ms 23752 KB Output is correct
37 Correct 13 ms 23820 KB Output is correct
38 Correct 14 ms 23764 KB Output is correct
39 Correct 15 ms 23792 KB Output is correct
40 Correct 15 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 13 ms 23816 KB Output is correct
43 Correct 14 ms 23760 KB Output is correct
44 Correct 13 ms 23764 KB Output is correct
45 Correct 13 ms 23720 KB Output is correct
46 Correct 13 ms 23764 KB Output is correct
47 Correct 13 ms 23772 KB Output is correct
48 Correct 14 ms 23748 KB Output is correct
49 Correct 14 ms 23764 KB Output is correct
50 Correct 13 ms 23764 KB Output is correct
51 Correct 16 ms 23764 KB Output is correct
52 Correct 18 ms 23764 KB Output is correct
53 Correct 13 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 13 ms 23732 KB Output is correct
56 Correct 13 ms 23812 KB Output is correct
57 Correct 14 ms 23892 KB Output is correct
58 Correct 15 ms 23892 KB Output is correct
59 Correct 14 ms 23892 KB Output is correct
60 Correct 13 ms 23904 KB Output is correct
61 Correct 15 ms 23868 KB Output is correct
62 Correct 13 ms 23912 KB Output is correct
63 Correct 14 ms 23892 KB Output is correct
64 Correct 13 ms 23892 KB Output is correct
65 Correct 13 ms 23892 KB Output is correct
66 Correct 15 ms 23892 KB Output is correct
67 Correct 16 ms 23892 KB Output is correct
68 Correct 15 ms 23892 KB Output is correct
69 Correct 15 ms 23896 KB Output is correct
70 Correct 13 ms 23892 KB Output is correct
71 Correct 16 ms 23872 KB Output is correct
72 Correct 16 ms 23908 KB Output is correct
73 Correct 13 ms 24020 KB Output is correct
74 Correct 14 ms 23988 KB Output is correct
75 Correct 13 ms 23956 KB Output is correct
76 Correct 13 ms 23960 KB Output is correct
77 Correct 18 ms 23828 KB Output is correct
78 Correct 13 ms 23856 KB Output is correct
79 Correct 14 ms 23912 KB Output is correct
80 Correct 13 ms 23880 KB Output is correct
81 Correct 15 ms 23940 KB Output is correct
82 Correct 13 ms 23880 KB Output is correct
83 Correct 13 ms 23872 KB Output is correct
84 Correct 16 ms 23764 KB Output is correct
85 Correct 13 ms 23760 KB Output is correct
86 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 16 ms 23764 KB Output is correct
3 Correct 13 ms 23696 KB Output is correct
4 Correct 14 ms 23716 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 14 ms 23824 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23708 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 14 ms 23764 KB Output is correct
15 Correct 16 ms 23708 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 13 ms 23816 KB Output is correct
18 Correct 13 ms 23788 KB Output is correct
19 Correct 14 ms 23688 KB Output is correct
20 Correct 14 ms 23724 KB Output is correct
21 Correct 14 ms 23720 KB Output is correct
22 Correct 13 ms 23764 KB Output is correct
23 Correct 13 ms 23788 KB Output is correct
24 Correct 13 ms 23804 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23812 KB Output is correct
27 Correct 13 ms 23808 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 13 ms 23696 KB Output is correct
30 Correct 14 ms 23764 KB Output is correct
31 Correct 13 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 14 ms 23800 KB Output is correct
34 Correct 16 ms 23820 KB Output is correct
35 Correct 12 ms 23784 KB Output is correct
36 Correct 13 ms 23752 KB Output is correct
37 Correct 13 ms 23820 KB Output is correct
38 Correct 14 ms 23764 KB Output is correct
39 Correct 15 ms 23792 KB Output is correct
40 Correct 15 ms 23764 KB Output is correct
41 Correct 14 ms 23764 KB Output is correct
42 Correct 13 ms 23816 KB Output is correct
43 Correct 14 ms 23760 KB Output is correct
44 Correct 13 ms 23764 KB Output is correct
45 Correct 13 ms 23720 KB Output is correct
46 Correct 13 ms 23764 KB Output is correct
47 Correct 13 ms 23772 KB Output is correct
48 Correct 14 ms 23748 KB Output is correct
49 Correct 14 ms 23764 KB Output is correct
50 Correct 13 ms 23764 KB Output is correct
51 Correct 16 ms 23764 KB Output is correct
52 Correct 18 ms 23764 KB Output is correct
53 Correct 13 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 13 ms 23732 KB Output is correct
56 Correct 13 ms 23812 KB Output is correct
57 Runtime error 155 ms 184036 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -