답안 #970213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970213 2024-04-26T08:04:53 Z berr Homework (CEOI22_homework) C++17
100 / 100
242 ms 400292 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
#define int long long


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s, k; cin >> s;
    int n = s.size();
    vector<int> type(n);
    vector<int> l(n, -1), r(n, -1), ma(n), mi(n), siz(n);
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='m'){
            if(s[i+1]=='a'){
                k+="+";
            }
            else k+="-";

            i+=2;
        }
        else k+=s[i];
    }

 //   cout<<k<<"\n";

    s = k;
    stack<int> st;
    int cnt=-1;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=',' && s[i]!= '(' && s[i]!= ')'){
                cnt++;

            if(st.size()){
                if(l[st.top()]==-1) l[st.top()] = cnt;
                else r[st.top()] = cnt, st.pop();
            }
            if(s[i]=='+'||s[i]=='-'){
                st.push(cnt);
                if(s[i]=='+') type[cnt] = 2;
                else type[cnt] = 1;
            }
        }
    }
/*
    for(int i=0; i<=cnt; i++){
        cout<<i<<" "<<l[i]<<" "<<r[i]<<" "<<type[i]<<"\n";
    }
*/

    auto dfs=[&](int v, auto&&dfs)->void{
        if(l[v]==-1 && r[v]==-1){
            ma[v] = 1; mi[v] = 1; siz[v]=1;
        }
        else{
            dfs(l[v], dfs); dfs(r[v], dfs);
            siz[v]+=siz[l[v]]+siz[r[v]];

            if(type[v]==2){
                ma[v] = max(siz[l[v]]+ma[r[v]], siz[r[v]]+ma[l[v]]);
                mi[v] = mi[l[v]]+mi[r[v]];
            }
            else{

                ma[v] = ma[l[v]]-1+ma[r[v]];
                mi[v] = min(mi[l[v]], mi[r[v]]);
            }
        }
    };

   
    dfs(0, dfs);

    cout<<ma[0]-mi[0]+1;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:19: 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]
   15 |     for(int i=0; i<s.size(); i++)
      |                  ~^~~~~~~~~
Main.cpp:34:19: 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]
   34 |     for(int i=0; i<s.size(); i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 452 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 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 1 ms 548 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 452 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 395468 KB Output is correct
2 Correct 210 ms 399384 KB Output is correct
3 Correct 241 ms 399020 KB Output is correct
4 Correct 213 ms 399180 KB Output is correct
5 Correct 206 ms 400088 KB Output is correct
6 Correct 201 ms 399340 KB Output is correct
7 Correct 212 ms 399008 KB Output is correct
8 Correct 201 ms 399716 KB Output is correct
9 Correct 207 ms 400076 KB Output is correct
10 Correct 205 ms 399112 KB Output is correct
11 Correct 202 ms 399080 KB Output is correct
12 Correct 209 ms 400044 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 452 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 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 1 ms 548 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 452 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 0 ms 604 KB Output is correct
59 Correct 0 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 0 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 1 ms 600 KB Output is correct
69 Correct 1 ms 604 KB Output is correct
70 Correct 1 ms 856 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 860 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 600 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 1 ms 600 KB Output is correct
81 Correct 1 ms 604 KB Output is correct
82 Correct 1 ms 712 KB Output is correct
83 Correct 1 ms 600 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 452 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 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 1 ms 548 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 452 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 203 ms 395468 KB Output is correct
58 Correct 210 ms 399384 KB Output is correct
59 Correct 241 ms 399020 KB Output is correct
60 Correct 213 ms 399180 KB Output is correct
61 Correct 206 ms 400088 KB Output is correct
62 Correct 201 ms 399340 KB Output is correct
63 Correct 212 ms 399008 KB Output is correct
64 Correct 201 ms 399716 KB Output is correct
65 Correct 207 ms 400076 KB Output is correct
66 Correct 205 ms 399112 KB Output is correct
67 Correct 202 ms 399080 KB Output is correct
68 Correct 209 ms 400044 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 0 ms 604 KB Output is correct
72 Correct 0 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 0 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 1 ms 604 KB Output is correct
81 Correct 1 ms 600 KB Output is correct
82 Correct 1 ms 604 KB Output is correct
83 Correct 1 ms 856 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 860 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 600 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 600 KB Output is correct
94 Correct 1 ms 604 KB Output is correct
95 Correct 1 ms 712 KB Output is correct
96 Correct 1 ms 600 KB Output is correct
97 Correct 1 ms 604 KB Output is correct
98 Correct 1 ms 604 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 178 ms 353272 KB Output is correct
101 Correct 181 ms 352780 KB Output is correct
102 Correct 168 ms 352628 KB Output is correct
103 Correct 169 ms 352352 KB Output is correct
104 Correct 167 ms 352388 KB Output is correct
105 Correct 191 ms 367824 KB Output is correct
106 Correct 193 ms 367888 KB Output is correct
107 Correct 188 ms 368212 KB Output is correct
108 Correct 195 ms 368588 KB Output is correct
109 Correct 188 ms 369364 KB Output is correct
110 Correct 179 ms 353500 KB Output is correct
111 Correct 182 ms 353204 KB Output is correct
112 Correct 183 ms 353492 KB Output is correct
113 Correct 173 ms 352140 KB Output is correct
114 Correct 174 ms 353232 KB Output is correct
115 Correct 242 ms 399500 KB Output is correct
116 Correct 220 ms 399008 KB Output is correct
117 Correct 213 ms 399776 KB Output is correct
118 Correct 238 ms 399048 KB Output is correct
119 Correct 203 ms 400292 KB Output is correct
120 Correct 174 ms 352936 KB Output is correct
121 Correct 170 ms 352108 KB Output is correct
122 Correct 180 ms 352372 KB Output is correct
123 Correct 177 ms 352760 KB Output is correct
124 Correct 176 ms 376360 KB Output is correct
125 Correct 181 ms 376544 KB Output is correct
126 Correct 178 ms 375840 KB Output is correct
127 Correct 175 ms 376772 KB Output is correct
128 Correct 78 ms 184784 KB Output is correct
129 Correct 72 ms 184788 KB Output is correct
130 Correct 71 ms 184868 KB Output is correct
131 Correct 1 ms 348 KB Output is correct