Submission #929254

# Submission time Handle Problem Language Result Execution time Memory
929254 2024-02-18T04:22:23 Z a_l_i_r_e_z_a Homework (CEOI22_homework) C++17
100 / 100
77 ms 35896 KB
// Be name Khoda
// Khodaya khodet komak kon
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define set_dec(x) cout << fixed << setprecision(x);
#define kill(x) cout << x << endl, exit(0)
#define sz(x) ((int)(x).size())
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

const ll maxN = 1e6 + 10;
const ll inf = 1e9 + 7;
stack<ll> op;
stack<pll> dp;
stack<ll> cnt;

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    string s; cin >> s;
    ll n = sz(s);

    for(int i = 0; i < n; i++){
        if(s[i] == 'm'){
            if(s[i + 1] == 'a') op.push(1);
            else op.push(0);
            i = i + 2;
        }
        else if(s[i] == '?'){
            dp.push(mp(1, 1));
            cnt.push(1);
        }
        else if(s[i] == ')'){
            ll operate = op.top();
            op.pop();

            pll r = dp.top();
            dp.pop();
            pll l = dp.top();
            dp.pop();

            ll cnt_r = cnt.top();
            cnt.pop();
            ll cnt_l = cnt.top();
            cnt.pop();
            
            if(operate){
                dp.push(mp(r.F + l.F, max(cnt_l + r.S, cnt_r + l.S)));
            }
            else{
                dp.push(mp(min(l.F, r.F), l.S + r.S - 1));
            }
            cnt.push(cnt_r + cnt_l); 
        }
    }

    pll ans = dp.top();

    cout << ans.S - ans.F + 1 << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 456 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 500 KB Output is correct
47 Correct 1 ms 496 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 35276 KB Output is correct
2 Correct 66 ms 35896 KB Output is correct
3 Correct 76 ms 34600 KB Output is correct
4 Correct 75 ms 34504 KB Output is correct
5 Correct 63 ms 35200 KB Output is correct
6 Correct 64 ms 35560 KB Output is correct
7 Correct 66 ms 34888 KB Output is correct
8 Correct 70 ms 34804 KB Output is correct
9 Correct 64 ms 35704 KB Output is correct
10 Correct 63 ms 35324 KB Output is correct
11 Correct 66 ms 34616 KB Output is correct
12 Correct 68 ms 35064 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 456 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 500 KB Output is correct
47 Correct 1 ms 496 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 464 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 544 KB Output is correct
62 Correct 0 ms 464 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 0 ms 504 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 460 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 460 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 0 ms 500 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 1 ms 344 KB Output is correct
82 Correct 1 ms 500 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 1 ms 344 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 456 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 500 KB Output is correct
47 Correct 1 ms 496 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 67 ms 35276 KB Output is correct
58 Correct 66 ms 35896 KB Output is correct
59 Correct 76 ms 34600 KB Output is correct
60 Correct 75 ms 34504 KB Output is correct
61 Correct 63 ms 35200 KB Output is correct
62 Correct 64 ms 35560 KB Output is correct
63 Correct 66 ms 34888 KB Output is correct
64 Correct 70 ms 34804 KB Output is correct
65 Correct 64 ms 35704 KB Output is correct
66 Correct 63 ms 35324 KB Output is correct
67 Correct 66 ms 34616 KB Output is correct
68 Correct 68 ms 35064 KB Output is correct
69 Correct 1 ms 460 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 464 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 1 ms 544 KB Output is correct
75 Correct 0 ms 464 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 0 ms 504 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 460 KB Output is correct
85 Correct 1 ms 348 KB Output is correct
86 Correct 1 ms 460 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 0 ms 500 KB Output is correct
93 Correct 1 ms 344 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 1 ms 500 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 1 ms 348 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 57 ms 14308 KB Output is correct
101 Correct 64 ms 14168 KB Output is correct
102 Correct 50 ms 14528 KB Output is correct
103 Correct 53 ms 14232 KB Output is correct
104 Correct 55 ms 14464 KB Output is correct
105 Correct 71 ms 20796 KB Output is correct
106 Correct 66 ms 22176 KB Output is correct
107 Correct 66 ms 21928 KB Output is correct
108 Correct 60 ms 20800 KB Output is correct
109 Correct 56 ms 21664 KB Output is correct
110 Correct 63 ms 15832 KB Output is correct
111 Correct 64 ms 14284 KB Output is correct
112 Correct 60 ms 14132 KB Output is correct
113 Correct 55 ms 14340 KB Output is correct
114 Correct 53 ms 14184 KB Output is correct
115 Correct 74 ms 34520 KB Output is correct
116 Correct 77 ms 35512 KB Output is correct
117 Correct 64 ms 34600 KB Output is correct
118 Correct 66 ms 34964 KB Output is correct
119 Correct 69 ms 35284 KB Output is correct
120 Correct 57 ms 15120 KB Output is correct
121 Correct 53 ms 14268 KB Output is correct
122 Correct 62 ms 15060 KB Output is correct
123 Correct 65 ms 14132 KB Output is correct
124 Correct 60 ms 31896 KB Output is correct
125 Correct 62 ms 31540 KB Output is correct
126 Correct 56 ms 31640 KB Output is correct
127 Correct 56 ms 30756 KB Output is correct
128 Correct 30 ms 9104 KB Output is correct
129 Correct 26 ms 8004 KB Output is correct
130 Correct 29 ms 7908 KB Output is correct
131 Correct 0 ms 344 KB Output is correct