Submission #667602

# Submission time Handle Problem Language Result Execution time Memory
667602 2022-12-01T18:54:08 Z Lobo Homework (CEOI22_homework) C++17
100 / 100
192 ms 202300 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = -1;

vector<int> rs;
string s;
pair<int,pair<int,int>> sol(int l, int r) {
    if(l == r) {
        return mp(1,mp(1,1));
    }
    int l1 = -1;
    for(int i = l+1;;i++) {
        if(rs[i] != -1) {
            l1 = i;
            break;
        }
    }
    int r1 = rs[l1];
    auto aux1 = sol(l1,r1);
    int sz1 = aux1.fr;
    int mn1 = aux1.sc.fr;
    int mx1 = aux1.sc.sc;


    int l2 = -1;
    for(int i = r1+1;;i++) {
        if(rs[i] != -1) {
            l2 = i;
            break;
        }
    }
    int r2 = rs[l2];
    auto aux2 = sol(l2,r2);
    int sz2 = aux2.fr;
    int mn2 = aux2.sc.fr;
    int mx2 = aux2.sc.sc;

    int sz = sz1+sz2;
    int mn,mx;
    if(s[l-1] == 'n') {
        mn = min(mn1,mn2);
        mx = mx1+mx2;
    }
    else {
        mn = mn1+mn2;
        mx = min(mx1,mx2);
    }
    return mp(sz,mp(mn,mx));
    return mp(0,mp(0,0));
}
void solve() {
    cin >> s;

    stack<int> ls;
    for(int i = 0; i < s.size(); i++) {
        rs.pb(-1);
        if(s[i] == '(') {
            ls.push(i);
        }
        else if(s[i] == ')') {
            rs[ls.top()] = i;
            ls.pop();
        }
        else if(s[i] == '?') {
            rs[i] = i;
        }
    }

    for(int i = 0; i < s.size(); i++) {
        if(rs[i] != -1) {
            // cout << i << " " << rs[i] << endl;
        }
    }

    int l = -1;
    for(int i = 0;; i++) {
        if(rs[i] != -1) {
            l = i;
            break;
        }
    }
    auto aux = sol(l,s.size()-1);
    int sz = aux.fr;
    int mn = aux.sc.fr;
    int mx = aux.sc.sc;
    cout << sz-(mn-1)-(mx-1) << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:65:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i = 0; i < s.size(); i++) {
      |                    ~~^~~~~~~~~~
Main.cpp:79:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0; i < s.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 288 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 201144 KB Output is correct
2 Correct 177 ms 201380 KB Output is correct
3 Correct 192 ms 201208 KB Output is correct
4 Correct 172 ms 202172 KB Output is correct
5 Correct 173 ms 201836 KB Output is correct
6 Correct 179 ms 202192 KB Output is correct
7 Correct 175 ms 201732 KB Output is correct
8 Correct 173 ms 201880 KB Output is correct
9 Correct 174 ms 201296 KB Output is correct
10 Correct 173 ms 201120 KB Output is correct
11 Correct 170 ms 202300 KB Output is correct
12 Correct 182 ms 201388 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 288 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 392 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 456 KB Output is correct
64 Correct 1 ms 468 KB Output is correct
65 Correct 1 ms 448 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 584 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 580 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 452 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 288 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 177 ms 201144 KB Output is correct
58 Correct 177 ms 201380 KB Output is correct
59 Correct 192 ms 201208 KB Output is correct
60 Correct 172 ms 202172 KB Output is correct
61 Correct 173 ms 201836 KB Output is correct
62 Correct 179 ms 202192 KB Output is correct
63 Correct 175 ms 201732 KB Output is correct
64 Correct 173 ms 201880 KB Output is correct
65 Correct 174 ms 201296 KB Output is correct
66 Correct 173 ms 201120 KB Output is correct
67 Correct 170 ms 202300 KB Output is correct
68 Correct 182 ms 201388 KB Output is correct
69 Correct 1 ms 316 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 340 KB Output is correct
74 Correct 1 ms 392 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 456 KB Output is correct
77 Correct 1 ms 468 KB Output is correct
78 Correct 1 ms 448 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 584 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 580 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 452 KB Output is correct
94 Correct 1 ms 468 KB Output is correct
95 Correct 1 ms 468 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 0 ms 340 KB Output is correct
99 Correct 0 ms 212 KB Output is correct
100 Correct 115 ms 83712 KB Output is correct
101 Correct 112 ms 83208 KB Output is correct
102 Correct 113 ms 83028 KB Output is correct
103 Correct 109 ms 83080 KB Output is correct
104 Correct 106 ms 82720 KB Output is correct
105 Correct 135 ms 113812 KB Output is correct
106 Correct 132 ms 113548 KB Output is correct
107 Correct 131 ms 113648 KB Output is correct
108 Correct 144 ms 114108 KB Output is correct
109 Correct 127 ms 114400 KB Output is correct
110 Correct 116 ms 83784 KB Output is correct
111 Correct 120 ms 83188 KB Output is correct
112 Correct 110 ms 83392 KB Output is correct
113 Correct 110 ms 82840 KB Output is correct
114 Correct 110 ms 83136 KB Output is correct
115 Correct 168 ms 202044 KB Output is correct
116 Correct 170 ms 201548 KB Output is correct
117 Correct 174 ms 201888 KB Output is correct
118 Correct 175 ms 201484 KB Output is correct
119 Correct 188 ms 201392 KB Output is correct
120 Correct 122 ms 83408 KB Output is correct
121 Correct 116 ms 83488 KB Output is correct
122 Correct 115 ms 83276 KB Output is correct
123 Correct 118 ms 83460 KB Output is correct
124 Correct 129 ms 135484 KB Output is correct
125 Correct 149 ms 135432 KB Output is correct
126 Correct 134 ms 135028 KB Output is correct
127 Correct 143 ms 135572 KB Output is correct
128 Correct 59 ms 42304 KB Output is correct
129 Correct 53 ms 42232 KB Output is correct
130 Correct 51 ms 42276 KB Output is correct
131 Correct 0 ms 212 KB Output is correct