Submission #994393

# Submission time Handle Problem Language Result Execution time Memory
994393 2024-06-07T14:19:51 Z biank Homework (CEOI22_homework) C++14
100 / 100
184 ms 207384 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) int(x.size())
#define all(x) begin(x),end(x)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define dbg(x) cerr<<#x<<": "<<x<<endl

#define pb push_back

typedef vector<int> vi;
typedef pair<int, int> ii;

const int MAXN=1e7+20;

string s;
int l[MAXN],r[MAXN];

struct Val{
    int l,r,sz;
    int cant(){return r-l+1;}
};

Val solve(int u){
    if(s[u]=='?') return {1,1,1};
    Val lch=solve(l[u]);
    Val rch=solve(r[u]);
    Val res;
    res.sz=lch.sz+rch.sz;
    if(s[u]=='n'){//min
        res.l=min(lch.l,rch.l);
        res.r=lch.r+rch.r-1;
    }else if(s[u]=='x'){//max
        res.l=lch.l+rch.l;
        res.r=max(rch.sz+lch.r,lch.sz+rch.r);
    }else assert(false);
    return res;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> s;
    memset(l, -1, sizeof l);
    memset(r, -1, sizeof r);
    stack<int> st;
    forn(i,sz(s)){
        if(s[i]=='n'||s[i]== 'x'||s[i]=='?'){
            st.push(i);
        }else if(s[i]==','||s[i]==')'){
            int j=st.top(); st.pop();
            if (l[st.top()] == -1) l[st.top()] = j;
            else r[st.top()] = j;
        }
    }
    cout<<solve(st.top()).cant()<<'\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 78684 KB Output is correct
2 Correct 8 ms 78684 KB Output is correct
3 Correct 10 ms 78684 KB Output is correct
4 Correct 10 ms 78684 KB Output is correct
5 Correct 9 ms 78696 KB Output is correct
6 Correct 10 ms 78684 KB Output is correct
7 Correct 9 ms 78676 KB Output is correct
8 Correct 10 ms 78684 KB Output is correct
9 Correct 9 ms 78680 KB Output is correct
10 Correct 10 ms 78708 KB Output is correct
11 Correct 9 ms 78596 KB Output is correct
12 Correct 9 ms 78608 KB Output is correct
13 Correct 11 ms 78680 KB Output is correct
14 Correct 10 ms 78720 KB Output is correct
15 Correct 10 ms 78608 KB Output is correct
16 Correct 12 ms 78684 KB Output is correct
17 Correct 9 ms 78684 KB Output is correct
18 Correct 9 ms 78684 KB Output is correct
19 Correct 10 ms 78684 KB Output is correct
20 Correct 9 ms 78676 KB Output is correct
21 Correct 8 ms 78684 KB Output is correct
22 Correct 9 ms 78684 KB Output is correct
23 Correct 8 ms 78608 KB Output is correct
24 Correct 10 ms 78684 KB Output is correct
25 Correct 9 ms 78684 KB Output is correct
26 Correct 11 ms 78684 KB Output is correct
27 Correct 9 ms 78684 KB Output is correct
28 Correct 9 ms 78684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 78684 KB Output is correct
2 Correct 8 ms 78684 KB Output is correct
3 Correct 10 ms 78684 KB Output is correct
4 Correct 10 ms 78684 KB Output is correct
5 Correct 9 ms 78696 KB Output is correct
6 Correct 10 ms 78684 KB Output is correct
7 Correct 9 ms 78676 KB Output is correct
8 Correct 10 ms 78684 KB Output is correct
9 Correct 9 ms 78680 KB Output is correct
10 Correct 10 ms 78708 KB Output is correct
11 Correct 9 ms 78596 KB Output is correct
12 Correct 9 ms 78608 KB Output is correct
13 Correct 11 ms 78680 KB Output is correct
14 Correct 10 ms 78720 KB Output is correct
15 Correct 10 ms 78608 KB Output is correct
16 Correct 12 ms 78684 KB Output is correct
17 Correct 9 ms 78684 KB Output is correct
18 Correct 9 ms 78684 KB Output is correct
19 Correct 10 ms 78684 KB Output is correct
20 Correct 9 ms 78676 KB Output is correct
21 Correct 8 ms 78684 KB Output is correct
22 Correct 9 ms 78684 KB Output is correct
23 Correct 8 ms 78608 KB Output is correct
24 Correct 10 ms 78684 KB Output is correct
25 Correct 9 ms 78684 KB Output is correct
26 Correct 11 ms 78684 KB Output is correct
27 Correct 9 ms 78684 KB Output is correct
28 Correct 9 ms 78684 KB Output is correct
29 Correct 10 ms 78684 KB Output is correct
30 Correct 10 ms 78576 KB Output is correct
31 Correct 10 ms 78680 KB Output is correct
32 Correct 9 ms 78584 KB Output is correct
33 Correct 10 ms 78700 KB Output is correct
34 Correct 10 ms 78684 KB Output is correct
35 Correct 10 ms 78684 KB Output is correct
36 Correct 10 ms 78684 KB Output is correct
37 Correct 9 ms 78708 KB Output is correct
38 Correct 9 ms 78684 KB Output is correct
39 Correct 9 ms 78684 KB Output is correct
40 Correct 9 ms 78680 KB Output is correct
41 Correct 8 ms 78684 KB Output is correct
42 Correct 10 ms 78684 KB Output is correct
43 Correct 10 ms 78684 KB Output is correct
44 Correct 9 ms 78684 KB Output is correct
45 Correct 9 ms 78684 KB Output is correct
46 Correct 9 ms 78684 KB Output is correct
47 Correct 9 ms 78684 KB Output is correct
48 Correct 8 ms 78720 KB Output is correct
49 Correct 9 ms 78684 KB Output is correct
50 Correct 10 ms 78684 KB Output is correct
51 Correct 9 ms 78684 KB Output is correct
52 Correct 9 ms 78576 KB Output is correct
53 Correct 9 ms 78684 KB Output is correct
54 Correct 9 ms 78684 KB Output is correct
55 Correct 9 ms 78584 KB Output is correct
56 Correct 9 ms 78684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 199020 KB Output is correct
2 Correct 139 ms 205892 KB Output is correct
3 Correct 142 ms 206540 KB Output is correct
4 Correct 143 ms 207052 KB Output is correct
5 Correct 184 ms 206912 KB Output is correct
6 Correct 137 ms 207056 KB Output is correct
7 Correct 140 ms 206028 KB Output is correct
8 Correct 130 ms 206032 KB Output is correct
9 Correct 133 ms 207384 KB Output is correct
10 Correct 128 ms 206160 KB Output is correct
11 Correct 137 ms 207120 KB Output is correct
12 Correct 142 ms 206028 KB Output is correct
13 Correct 10 ms 78680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 78684 KB Output is correct
2 Correct 8 ms 78684 KB Output is correct
3 Correct 10 ms 78684 KB Output is correct
4 Correct 10 ms 78684 KB Output is correct
5 Correct 9 ms 78696 KB Output is correct
6 Correct 10 ms 78684 KB Output is correct
7 Correct 9 ms 78676 KB Output is correct
8 Correct 10 ms 78684 KB Output is correct
9 Correct 9 ms 78680 KB Output is correct
10 Correct 10 ms 78708 KB Output is correct
11 Correct 9 ms 78596 KB Output is correct
12 Correct 9 ms 78608 KB Output is correct
13 Correct 11 ms 78680 KB Output is correct
14 Correct 10 ms 78720 KB Output is correct
15 Correct 10 ms 78608 KB Output is correct
16 Correct 12 ms 78684 KB Output is correct
17 Correct 9 ms 78684 KB Output is correct
18 Correct 9 ms 78684 KB Output is correct
19 Correct 10 ms 78684 KB Output is correct
20 Correct 9 ms 78676 KB Output is correct
21 Correct 8 ms 78684 KB Output is correct
22 Correct 9 ms 78684 KB Output is correct
23 Correct 8 ms 78608 KB Output is correct
24 Correct 10 ms 78684 KB Output is correct
25 Correct 9 ms 78684 KB Output is correct
26 Correct 11 ms 78684 KB Output is correct
27 Correct 9 ms 78684 KB Output is correct
28 Correct 9 ms 78684 KB Output is correct
29 Correct 10 ms 78684 KB Output is correct
30 Correct 10 ms 78576 KB Output is correct
31 Correct 10 ms 78680 KB Output is correct
32 Correct 9 ms 78584 KB Output is correct
33 Correct 10 ms 78700 KB Output is correct
34 Correct 10 ms 78684 KB Output is correct
35 Correct 10 ms 78684 KB Output is correct
36 Correct 10 ms 78684 KB Output is correct
37 Correct 9 ms 78708 KB Output is correct
38 Correct 9 ms 78684 KB Output is correct
39 Correct 9 ms 78684 KB Output is correct
40 Correct 9 ms 78680 KB Output is correct
41 Correct 8 ms 78684 KB Output is correct
42 Correct 10 ms 78684 KB Output is correct
43 Correct 10 ms 78684 KB Output is correct
44 Correct 9 ms 78684 KB Output is correct
45 Correct 9 ms 78684 KB Output is correct
46 Correct 9 ms 78684 KB Output is correct
47 Correct 9 ms 78684 KB Output is correct
48 Correct 8 ms 78720 KB Output is correct
49 Correct 9 ms 78684 KB Output is correct
50 Correct 10 ms 78684 KB Output is correct
51 Correct 9 ms 78684 KB Output is correct
52 Correct 9 ms 78576 KB Output is correct
53 Correct 9 ms 78684 KB Output is correct
54 Correct 9 ms 78684 KB Output is correct
55 Correct 9 ms 78584 KB Output is correct
56 Correct 9 ms 78684 KB Output is correct
57 Correct 9 ms 78684 KB Output is correct
58 Correct 9 ms 78684 KB Output is correct
59 Correct 9 ms 78684 KB Output is correct
60 Correct 9 ms 78684 KB Output is correct
61 Correct 11 ms 78680 KB Output is correct
62 Correct 10 ms 78780 KB Output is correct
63 Correct 10 ms 78588 KB Output is correct
64 Correct 9 ms 78736 KB Output is correct
65 Correct 10 ms 78680 KB Output is correct
66 Correct 9 ms 78684 KB Output is correct
67 Correct 9 ms 78560 KB Output is correct
68 Correct 9 ms 78684 KB Output is correct
69 Correct 9 ms 78576 KB Output is correct
70 Correct 9 ms 78680 KB Output is correct
71 Correct 9 ms 78680 KB Output is correct
72 Correct 9 ms 78684 KB Output is correct
73 Correct 10 ms 78692 KB Output is correct
74 Correct 9 ms 78680 KB Output is correct
75 Correct 9 ms 78684 KB Output is correct
76 Correct 10 ms 78828 KB Output is correct
77 Correct 9 ms 78596 KB Output is correct
78 Correct 10 ms 78680 KB Output is correct
79 Correct 9 ms 78572 KB Output is correct
80 Correct 10 ms 78684 KB Output is correct
81 Correct 10 ms 78684 KB Output is correct
82 Correct 9 ms 78712 KB Output is correct
83 Correct 10 ms 78684 KB Output is correct
84 Correct 10 ms 78684 KB Output is correct
85 Correct 9 ms 78684 KB Output is correct
86 Correct 9 ms 78580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 78684 KB Output is correct
2 Correct 8 ms 78684 KB Output is correct
3 Correct 10 ms 78684 KB Output is correct
4 Correct 10 ms 78684 KB Output is correct
5 Correct 9 ms 78696 KB Output is correct
6 Correct 10 ms 78684 KB Output is correct
7 Correct 9 ms 78676 KB Output is correct
8 Correct 10 ms 78684 KB Output is correct
9 Correct 9 ms 78680 KB Output is correct
10 Correct 10 ms 78708 KB Output is correct
11 Correct 9 ms 78596 KB Output is correct
12 Correct 9 ms 78608 KB Output is correct
13 Correct 11 ms 78680 KB Output is correct
14 Correct 10 ms 78720 KB Output is correct
15 Correct 10 ms 78608 KB Output is correct
16 Correct 12 ms 78684 KB Output is correct
17 Correct 9 ms 78684 KB Output is correct
18 Correct 9 ms 78684 KB Output is correct
19 Correct 10 ms 78684 KB Output is correct
20 Correct 9 ms 78676 KB Output is correct
21 Correct 8 ms 78684 KB Output is correct
22 Correct 9 ms 78684 KB Output is correct
23 Correct 8 ms 78608 KB Output is correct
24 Correct 10 ms 78684 KB Output is correct
25 Correct 9 ms 78684 KB Output is correct
26 Correct 11 ms 78684 KB Output is correct
27 Correct 9 ms 78684 KB Output is correct
28 Correct 9 ms 78684 KB Output is correct
29 Correct 10 ms 78684 KB Output is correct
30 Correct 10 ms 78576 KB Output is correct
31 Correct 10 ms 78680 KB Output is correct
32 Correct 9 ms 78584 KB Output is correct
33 Correct 10 ms 78700 KB Output is correct
34 Correct 10 ms 78684 KB Output is correct
35 Correct 10 ms 78684 KB Output is correct
36 Correct 10 ms 78684 KB Output is correct
37 Correct 9 ms 78708 KB Output is correct
38 Correct 9 ms 78684 KB Output is correct
39 Correct 9 ms 78684 KB Output is correct
40 Correct 9 ms 78680 KB Output is correct
41 Correct 8 ms 78684 KB Output is correct
42 Correct 10 ms 78684 KB Output is correct
43 Correct 10 ms 78684 KB Output is correct
44 Correct 9 ms 78684 KB Output is correct
45 Correct 9 ms 78684 KB Output is correct
46 Correct 9 ms 78684 KB Output is correct
47 Correct 9 ms 78684 KB Output is correct
48 Correct 8 ms 78720 KB Output is correct
49 Correct 9 ms 78684 KB Output is correct
50 Correct 10 ms 78684 KB Output is correct
51 Correct 9 ms 78684 KB Output is correct
52 Correct 9 ms 78576 KB Output is correct
53 Correct 9 ms 78684 KB Output is correct
54 Correct 9 ms 78684 KB Output is correct
55 Correct 9 ms 78584 KB Output is correct
56 Correct 9 ms 78684 KB Output is correct
57 Correct 135 ms 199020 KB Output is correct
58 Correct 139 ms 205892 KB Output is correct
59 Correct 142 ms 206540 KB Output is correct
60 Correct 143 ms 207052 KB Output is correct
61 Correct 184 ms 206912 KB Output is correct
62 Correct 137 ms 207056 KB Output is correct
63 Correct 140 ms 206028 KB Output is correct
64 Correct 130 ms 206032 KB Output is correct
65 Correct 133 ms 207384 KB Output is correct
66 Correct 128 ms 206160 KB Output is correct
67 Correct 137 ms 207120 KB Output is correct
68 Correct 142 ms 206028 KB Output is correct
69 Correct 10 ms 78680 KB Output is correct
70 Correct 9 ms 78684 KB Output is correct
71 Correct 9 ms 78684 KB Output is correct
72 Correct 9 ms 78684 KB Output is correct
73 Correct 9 ms 78684 KB Output is correct
74 Correct 11 ms 78680 KB Output is correct
75 Correct 10 ms 78780 KB Output is correct
76 Correct 10 ms 78588 KB Output is correct
77 Correct 9 ms 78736 KB Output is correct
78 Correct 10 ms 78680 KB Output is correct
79 Correct 9 ms 78684 KB Output is correct
80 Correct 9 ms 78560 KB Output is correct
81 Correct 9 ms 78684 KB Output is correct
82 Correct 9 ms 78576 KB Output is correct
83 Correct 9 ms 78680 KB Output is correct
84 Correct 9 ms 78680 KB Output is correct
85 Correct 9 ms 78684 KB Output is correct
86 Correct 10 ms 78692 KB Output is correct
87 Correct 9 ms 78680 KB Output is correct
88 Correct 9 ms 78684 KB Output is correct
89 Correct 10 ms 78828 KB Output is correct
90 Correct 9 ms 78596 KB Output is correct
91 Correct 10 ms 78680 KB Output is correct
92 Correct 9 ms 78572 KB Output is correct
93 Correct 10 ms 78684 KB Output is correct
94 Correct 10 ms 78684 KB Output is correct
95 Correct 9 ms 78712 KB Output is correct
96 Correct 10 ms 78684 KB Output is correct
97 Correct 10 ms 78684 KB Output is correct
98 Correct 9 ms 78684 KB Output is correct
99 Correct 9 ms 78580 KB Output is correct
100 Correct 57 ms 93140 KB Output is correct
101 Correct 58 ms 92992 KB Output is correct
102 Correct 57 ms 93584 KB Output is correct
103 Correct 54 ms 92368 KB Output is correct
104 Correct 56 ms 92468 KB Output is correct
105 Correct 84 ms 130512 KB Output is correct
106 Correct 82 ms 131020 KB Output is correct
107 Correct 86 ms 130100 KB Output is correct
108 Correct 80 ms 131280 KB Output is correct
109 Correct 81 ms 130256 KB Output is correct
110 Correct 61 ms 92660 KB Output is correct
111 Correct 62 ms 92832 KB Output is correct
112 Correct 57 ms 92372 KB Output is correct
113 Correct 58 ms 92368 KB Output is correct
114 Correct 59 ms 93528 KB Output is correct
115 Correct 137 ms 206288 KB Output is correct
116 Correct 134 ms 205964 KB Output is correct
117 Correct 131 ms 207224 KB Output is correct
118 Correct 132 ms 206888 KB Output is correct
119 Correct 136 ms 207052 KB Output is correct
120 Correct 58 ms 92880 KB Output is correct
121 Correct 58 ms 93648 KB Output is correct
122 Correct 62 ms 93652 KB Output is correct
123 Correct 64 ms 92724 KB Output is correct
124 Correct 84 ms 149652 KB Output is correct
125 Correct 90 ms 149456 KB Output is correct
126 Correct 85 ms 150068 KB Output is correct
127 Correct 82 ms 149452 KB Output is correct
128 Correct 29 ms 85808 KB Output is correct
129 Correct 29 ms 85980 KB Output is correct
130 Correct 28 ms 85984 KB Output is correct
131 Correct 9 ms 78680 KB Output is correct