Submission #1030676

# Submission time Handle Problem Language Result Execution time Memory
1030676 2024-07-22T08:27:11 Z mispertion Homework (CEOI22_homework) C++17
100 / 100
156 ms 167136 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
 
const ld PI = 3.1415926535;
const int N = 3e6+10;
const int M = 1e4 + 5;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 467743;
 
int mult(int a, int b) {
    return a * 1LL * b % mod;
}
 
int sum(int a, int b) {
    a %= mod;
    b %= mod; 
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}
 
int binpow(int a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return mult(binpow(a, n - 1), a);
    } else {
        int b = binpow(a, n / 2);
        return mult(b, b);
    }
}

int n, tp[N], cr, l[N], r[N];
string expr;
vector<int> g[N];

void solve(){
    cin >> expr;
    int mx = sz(expr);
    expr += "$$";
    int i = 0;
    stack<int> st;
    while(i < mx){
        if(expr[i] == 'm'){
            cr++;
            if(sz(st) > 0)
                g[st.top()].pb(cr);
            st.push(cr);
            if(expr[i + 1] == 'i')
                tp[cr] = -1;
            else
                tp[cr] = 1;
            i += 4;
        }else if(expr[i] == '?'){
            n++;
            cr++;
            if(sz(st) > 0)
                g[st.top()].pb(cr);
            while(expr[i + 1] == ')'){
                st.pop();
                i++;
            }
            i += 2;
        }
    }    
    for(int v = cr; v >= 1; v--){
        if(tp[v] == 0){
            l[v] = 0;
            r[v] = 0;
        }else if(tp[v] == 1){
            r[v] = min(r[g[v][0]], r[g[v][1]]);
            l[v] = l[g[v][0]] + l[g[v][1]] + 1;
        }else{
            l[v] = min(l[g[v][0]], l[g[v][1]]);
            r[v] = r[g[v][0]] + r[g[v][1]] + 1;
        }
    }
    cout << n - l[1] - r[1] << '\n';
}

signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

// coded by mispertion :)
# Verdict Execution time Memory Grader output
1 Correct 16 ms 72288 KB Output is correct
2 Correct 18 ms 72420 KB Output is correct
3 Correct 16 ms 72480 KB Output is correct
4 Correct 25 ms 72288 KB Output is correct
5 Correct 24 ms 72540 KB Output is correct
6 Correct 18 ms 72320 KB Output is correct
7 Correct 16 ms 72280 KB Output is correct
8 Correct 19 ms 74336 KB Output is correct
9 Correct 16 ms 72284 KB Output is correct
10 Correct 16 ms 72284 KB Output is correct
11 Correct 18 ms 72280 KB Output is correct
12 Correct 19 ms 72284 KB Output is correct
13 Correct 15 ms 72396 KB Output is correct
14 Correct 16 ms 72280 KB Output is correct
15 Correct 16 ms 72280 KB Output is correct
16 Correct 15 ms 72536 KB Output is correct
17 Correct 17 ms 72328 KB Output is correct
18 Correct 16 ms 72480 KB Output is correct
19 Correct 15 ms 72280 KB Output is correct
20 Correct 17 ms 72280 KB Output is correct
21 Correct 17 ms 72380 KB Output is correct
22 Correct 17 ms 72280 KB Output is correct
23 Correct 16 ms 72284 KB Output is correct
24 Correct 16 ms 72280 KB Output is correct
25 Correct 16 ms 72284 KB Output is correct
26 Correct 17 ms 72324 KB Output is correct
27 Correct 17 ms 72284 KB Output is correct
28 Correct 17 ms 72452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 72288 KB Output is correct
2 Correct 18 ms 72420 KB Output is correct
3 Correct 16 ms 72480 KB Output is correct
4 Correct 25 ms 72288 KB Output is correct
5 Correct 24 ms 72540 KB Output is correct
6 Correct 18 ms 72320 KB Output is correct
7 Correct 16 ms 72280 KB Output is correct
8 Correct 19 ms 74336 KB Output is correct
9 Correct 16 ms 72284 KB Output is correct
10 Correct 16 ms 72284 KB Output is correct
11 Correct 18 ms 72280 KB Output is correct
12 Correct 19 ms 72284 KB Output is correct
13 Correct 15 ms 72396 KB Output is correct
14 Correct 16 ms 72280 KB Output is correct
15 Correct 16 ms 72280 KB Output is correct
16 Correct 15 ms 72536 KB Output is correct
17 Correct 17 ms 72328 KB Output is correct
18 Correct 16 ms 72480 KB Output is correct
19 Correct 15 ms 72280 KB Output is correct
20 Correct 17 ms 72280 KB Output is correct
21 Correct 17 ms 72380 KB Output is correct
22 Correct 17 ms 72280 KB Output is correct
23 Correct 16 ms 72284 KB Output is correct
24 Correct 16 ms 72280 KB Output is correct
25 Correct 16 ms 72284 KB Output is correct
26 Correct 17 ms 72324 KB Output is correct
27 Correct 17 ms 72284 KB Output is correct
28 Correct 17 ms 72452 KB Output is correct
29 Correct 18 ms 72536 KB Output is correct
30 Correct 16 ms 72284 KB Output is correct
31 Correct 16 ms 72260 KB Output is correct
32 Correct 19 ms 72368 KB Output is correct
33 Correct 17 ms 72284 KB Output is correct
34 Correct 17 ms 72284 KB Output is correct
35 Correct 15 ms 72280 KB Output is correct
36 Correct 15 ms 72284 KB Output is correct
37 Correct 17 ms 72284 KB Output is correct
38 Correct 16 ms 72284 KB Output is correct
39 Correct 17 ms 72280 KB Output is correct
40 Correct 15 ms 72284 KB Output is correct
41 Correct 16 ms 72352 KB Output is correct
42 Correct 16 ms 72284 KB Output is correct
43 Correct 16 ms 72280 KB Output is correct
44 Correct 17 ms 72280 KB Output is correct
45 Correct 16 ms 72452 KB Output is correct
46 Correct 16 ms 72332 KB Output is correct
47 Correct 16 ms 72372 KB Output is correct
48 Correct 16 ms 72280 KB Output is correct
49 Correct 16 ms 72288 KB Output is correct
50 Correct 15 ms 72292 KB Output is correct
51 Correct 16 ms 72284 KB Output is correct
52 Correct 16 ms 72436 KB Output is correct
53 Correct 18 ms 72284 KB Output is correct
54 Correct 16 ms 72284 KB Output is correct
55 Correct 15 ms 72308 KB Output is correct
56 Correct 17 ms 72280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 167004 KB Output is correct
2 Correct 130 ms 167112 KB Output is correct
3 Correct 156 ms 167120 KB Output is correct
4 Correct 145 ms 167112 KB Output is correct
5 Correct 141 ms 167116 KB Output is correct
6 Correct 137 ms 166968 KB Output is correct
7 Correct 139 ms 167136 KB Output is correct
8 Correct 145 ms 167116 KB Output is correct
9 Correct 141 ms 167064 KB Output is correct
10 Correct 153 ms 167112 KB Output is correct
11 Correct 135 ms 167120 KB Output is correct
12 Correct 140 ms 167076 KB Output is correct
13 Correct 18 ms 72280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 72288 KB Output is correct
2 Correct 18 ms 72420 KB Output is correct
3 Correct 16 ms 72480 KB Output is correct
4 Correct 25 ms 72288 KB Output is correct
5 Correct 24 ms 72540 KB Output is correct
6 Correct 18 ms 72320 KB Output is correct
7 Correct 16 ms 72280 KB Output is correct
8 Correct 19 ms 74336 KB Output is correct
9 Correct 16 ms 72284 KB Output is correct
10 Correct 16 ms 72284 KB Output is correct
11 Correct 18 ms 72280 KB Output is correct
12 Correct 19 ms 72284 KB Output is correct
13 Correct 15 ms 72396 KB Output is correct
14 Correct 16 ms 72280 KB Output is correct
15 Correct 16 ms 72280 KB Output is correct
16 Correct 15 ms 72536 KB Output is correct
17 Correct 17 ms 72328 KB Output is correct
18 Correct 16 ms 72480 KB Output is correct
19 Correct 15 ms 72280 KB Output is correct
20 Correct 17 ms 72280 KB Output is correct
21 Correct 17 ms 72380 KB Output is correct
22 Correct 17 ms 72280 KB Output is correct
23 Correct 16 ms 72284 KB Output is correct
24 Correct 16 ms 72280 KB Output is correct
25 Correct 16 ms 72284 KB Output is correct
26 Correct 17 ms 72324 KB Output is correct
27 Correct 17 ms 72284 KB Output is correct
28 Correct 17 ms 72452 KB Output is correct
29 Correct 18 ms 72536 KB Output is correct
30 Correct 16 ms 72284 KB Output is correct
31 Correct 16 ms 72260 KB Output is correct
32 Correct 19 ms 72368 KB Output is correct
33 Correct 17 ms 72284 KB Output is correct
34 Correct 17 ms 72284 KB Output is correct
35 Correct 15 ms 72280 KB Output is correct
36 Correct 15 ms 72284 KB Output is correct
37 Correct 17 ms 72284 KB Output is correct
38 Correct 16 ms 72284 KB Output is correct
39 Correct 17 ms 72280 KB Output is correct
40 Correct 15 ms 72284 KB Output is correct
41 Correct 16 ms 72352 KB Output is correct
42 Correct 16 ms 72284 KB Output is correct
43 Correct 16 ms 72280 KB Output is correct
44 Correct 17 ms 72280 KB Output is correct
45 Correct 16 ms 72452 KB Output is correct
46 Correct 16 ms 72332 KB Output is correct
47 Correct 16 ms 72372 KB Output is correct
48 Correct 16 ms 72280 KB Output is correct
49 Correct 16 ms 72288 KB Output is correct
50 Correct 15 ms 72292 KB Output is correct
51 Correct 16 ms 72284 KB Output is correct
52 Correct 16 ms 72436 KB Output is correct
53 Correct 18 ms 72284 KB Output is correct
54 Correct 16 ms 72284 KB Output is correct
55 Correct 15 ms 72308 KB Output is correct
56 Correct 17 ms 72280 KB Output is correct
57 Correct 16 ms 72536 KB Output is correct
58 Correct 16 ms 72532 KB Output is correct
59 Correct 15 ms 72340 KB Output is correct
60 Correct 16 ms 72540 KB Output is correct
61 Correct 17 ms 72540 KB Output is correct
62 Correct 17 ms 72332 KB Output is correct
63 Correct 21 ms 72416 KB Output is correct
64 Correct 19 ms 72380 KB Output is correct
65 Correct 21 ms 72540 KB Output is correct
66 Correct 17 ms 72336 KB Output is correct
67 Correct 17 ms 72540 KB Output is correct
68 Correct 16 ms 72540 KB Output is correct
69 Correct 16 ms 72540 KB Output is correct
70 Correct 17 ms 72460 KB Output is correct
71 Correct 19 ms 72376 KB Output is correct
72 Correct 16 ms 72536 KB Output is correct
73 Correct 16 ms 72540 KB Output is correct
74 Correct 17 ms 72528 KB Output is correct
75 Correct 17 ms 72540 KB Output is correct
76 Correct 15 ms 72536 KB Output is correct
77 Correct 17 ms 72540 KB Output is correct
78 Correct 16 ms 72532 KB Output is correct
79 Correct 15 ms 72536 KB Output is correct
80 Correct 16 ms 72540 KB Output is correct
81 Correct 15 ms 72540 KB Output is correct
82 Correct 17 ms 72560 KB Output is correct
83 Correct 16 ms 72528 KB Output is correct
84 Correct 16 ms 72280 KB Output is correct
85 Correct 17 ms 72280 KB Output is correct
86 Correct 16 ms 72284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 72288 KB Output is correct
2 Correct 18 ms 72420 KB Output is correct
3 Correct 16 ms 72480 KB Output is correct
4 Correct 25 ms 72288 KB Output is correct
5 Correct 24 ms 72540 KB Output is correct
6 Correct 18 ms 72320 KB Output is correct
7 Correct 16 ms 72280 KB Output is correct
8 Correct 19 ms 74336 KB Output is correct
9 Correct 16 ms 72284 KB Output is correct
10 Correct 16 ms 72284 KB Output is correct
11 Correct 18 ms 72280 KB Output is correct
12 Correct 19 ms 72284 KB Output is correct
13 Correct 15 ms 72396 KB Output is correct
14 Correct 16 ms 72280 KB Output is correct
15 Correct 16 ms 72280 KB Output is correct
16 Correct 15 ms 72536 KB Output is correct
17 Correct 17 ms 72328 KB Output is correct
18 Correct 16 ms 72480 KB Output is correct
19 Correct 15 ms 72280 KB Output is correct
20 Correct 17 ms 72280 KB Output is correct
21 Correct 17 ms 72380 KB Output is correct
22 Correct 17 ms 72280 KB Output is correct
23 Correct 16 ms 72284 KB Output is correct
24 Correct 16 ms 72280 KB Output is correct
25 Correct 16 ms 72284 KB Output is correct
26 Correct 17 ms 72324 KB Output is correct
27 Correct 17 ms 72284 KB Output is correct
28 Correct 17 ms 72452 KB Output is correct
29 Correct 18 ms 72536 KB Output is correct
30 Correct 16 ms 72284 KB Output is correct
31 Correct 16 ms 72260 KB Output is correct
32 Correct 19 ms 72368 KB Output is correct
33 Correct 17 ms 72284 KB Output is correct
34 Correct 17 ms 72284 KB Output is correct
35 Correct 15 ms 72280 KB Output is correct
36 Correct 15 ms 72284 KB Output is correct
37 Correct 17 ms 72284 KB Output is correct
38 Correct 16 ms 72284 KB Output is correct
39 Correct 17 ms 72280 KB Output is correct
40 Correct 15 ms 72284 KB Output is correct
41 Correct 16 ms 72352 KB Output is correct
42 Correct 16 ms 72284 KB Output is correct
43 Correct 16 ms 72280 KB Output is correct
44 Correct 17 ms 72280 KB Output is correct
45 Correct 16 ms 72452 KB Output is correct
46 Correct 16 ms 72332 KB Output is correct
47 Correct 16 ms 72372 KB Output is correct
48 Correct 16 ms 72280 KB Output is correct
49 Correct 16 ms 72288 KB Output is correct
50 Correct 15 ms 72292 KB Output is correct
51 Correct 16 ms 72284 KB Output is correct
52 Correct 16 ms 72436 KB Output is correct
53 Correct 18 ms 72284 KB Output is correct
54 Correct 16 ms 72284 KB Output is correct
55 Correct 15 ms 72308 KB Output is correct
56 Correct 17 ms 72280 KB Output is correct
57 Correct 140 ms 167004 KB Output is correct
58 Correct 130 ms 167112 KB Output is correct
59 Correct 156 ms 167120 KB Output is correct
60 Correct 145 ms 167112 KB Output is correct
61 Correct 141 ms 167116 KB Output is correct
62 Correct 137 ms 166968 KB Output is correct
63 Correct 139 ms 167136 KB Output is correct
64 Correct 145 ms 167116 KB Output is correct
65 Correct 141 ms 167064 KB Output is correct
66 Correct 153 ms 167112 KB Output is correct
67 Correct 135 ms 167120 KB Output is correct
68 Correct 140 ms 167076 KB Output is correct
69 Correct 18 ms 72280 KB Output is correct
70 Correct 16 ms 72536 KB Output is correct
71 Correct 16 ms 72532 KB Output is correct
72 Correct 15 ms 72340 KB Output is correct
73 Correct 16 ms 72540 KB Output is correct
74 Correct 17 ms 72540 KB Output is correct
75 Correct 17 ms 72332 KB Output is correct
76 Correct 21 ms 72416 KB Output is correct
77 Correct 19 ms 72380 KB Output is correct
78 Correct 21 ms 72540 KB Output is correct
79 Correct 17 ms 72336 KB Output is correct
80 Correct 17 ms 72540 KB Output is correct
81 Correct 16 ms 72540 KB Output is correct
82 Correct 16 ms 72540 KB Output is correct
83 Correct 17 ms 72460 KB Output is correct
84 Correct 19 ms 72376 KB Output is correct
85 Correct 16 ms 72536 KB Output is correct
86 Correct 16 ms 72540 KB Output is correct
87 Correct 17 ms 72528 KB Output is correct
88 Correct 17 ms 72540 KB Output is correct
89 Correct 15 ms 72536 KB Output is correct
90 Correct 17 ms 72540 KB Output is correct
91 Correct 16 ms 72532 KB Output is correct
92 Correct 15 ms 72536 KB Output is correct
93 Correct 16 ms 72540 KB Output is correct
94 Correct 15 ms 72540 KB Output is correct
95 Correct 17 ms 72560 KB Output is correct
96 Correct 16 ms 72528 KB Output is correct
97 Correct 16 ms 72280 KB Output is correct
98 Correct 17 ms 72280 KB Output is correct
99 Correct 16 ms 72284 KB Output is correct
100 Correct 136 ms 162688 KB Output is correct
101 Correct 136 ms 162884 KB Output is correct
102 Correct 127 ms 162888 KB Output is correct
103 Correct 128 ms 162760 KB Output is correct
104 Correct 126 ms 162760 KB Output is correct
105 Correct 152 ms 162952 KB Output is correct
106 Correct 152 ms 162940 KB Output is correct
107 Correct 145 ms 163016 KB Output is correct
108 Correct 142 ms 162848 KB Output is correct
109 Correct 145 ms 163020 KB Output is correct
110 Correct 141 ms 162764 KB Output is correct
111 Correct 138 ms 162764 KB Output is correct
112 Correct 146 ms 162736 KB Output is correct
113 Correct 141 ms 163016 KB Output is correct
114 Correct 131 ms 162764 KB Output is correct
115 Correct 150 ms 167028 KB Output is correct
116 Correct 149 ms 166956 KB Output is correct
117 Correct 144 ms 167040 KB Output is correct
118 Correct 138 ms 166992 KB Output is correct
119 Correct 133 ms 166988 KB Output is correct
120 Correct 131 ms 162904 KB Output is correct
121 Correct 131 ms 162764 KB Output is correct
122 Correct 153 ms 162816 KB Output is correct
123 Correct 142 ms 162684 KB Output is correct
124 Correct 128 ms 166836 KB Output is correct
125 Correct 130 ms 166956 KB Output is correct
126 Correct 124 ms 167004 KB Output is correct
127 Correct 122 ms 166856 KB Output is correct
128 Correct 72 ms 118996 KB Output is correct
129 Correct 73 ms 118924 KB Output is correct
130 Correct 67 ms 118992 KB Output is correct
131 Correct 17 ms 72280 KB Output is correct