답안 #943381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943381 2024-03-11T12:32:09 Z Ahmed57 Homework (CEOI22_homework) C++17
100 / 100
309 ms 437128 KB
#include "bits/stdc++.h"

using namespace std;
#ifdef LOCAL
#include "debug.cpp"
#else
#define debug(...)
#endif
int NODES = 0;
string s;
int L[10000001],R[10000001],nah[10000001];
int pref[10000001];
vector<int> v[10000001];
int query(int l,int r){
    return pref[r]-(l==0?0:pref[l-1]);
}
int rec(int l,int r){
    if(l==r){
        return nah[l];
    }
    NODES++;
    int p1 = rec(l+4,v[l][1]-2);
    int p2 = rec(v[l][1],r-1);
    int l1 = l+4 , r1 = v[l][1]-2;
    int l2 = v[l][1] , r2 = r-1;
    if(s[l+2]=='x'){
        R[NODES] = query(l,r)-min(query(l1,r1)-R[p1],query(l2,r2)-R[p2]);
        L[NODES] = query(l,r)-(query(l1,r1)-L[p1])-(query(l2,r2)-L[p2]);
    }else {
        L[NODES] = min(L[p1],L[p2]);
        R[NODES] = R[p1]+R[p2]-1;
    }
    return NODES;
}
signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>s;
    int i = 0;
    stack<int> st;
    while(i<s.size()){
        if(s[i]=='m'){
            if(!st.empty()){
                v[st.top()].push_back(i);
            }
            st.push(i);
            i+=4;
        }if(s[i]=='?'){
            if(!st.empty()){
                v[st.top()].push_back(i);
            }
            i++;
        }if(s[i]==')'){
            st.pop();
            i++;
        }if(s[i]==',')i++;
    }
    for(int i = 0;i<s.size();i++){
        if(s[i]=='?'){
            pref[i] = 1;
            L[NODES] = 1;
            R[NODES] = 1;
            nah[i] = NODES;
            NODES++;
        }
        if(i)pref[i]+=pref[i-1];
    }
    int nah = rec(0,s.size()-1);
    cout<<R[nah]-L[nah]+1<<endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while(i<s.size()){
      |           ~^~~~~~~~~
Main.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0;i<s.size();i++){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 242636 KB Output is correct
2 Correct 53 ms 242516 KB Output is correct
3 Correct 54 ms 242648 KB Output is correct
4 Correct 53 ms 242512 KB Output is correct
5 Correct 55 ms 242500 KB Output is correct
6 Correct 53 ms 242512 KB Output is correct
7 Correct 56 ms 242876 KB Output is correct
8 Correct 58 ms 242712 KB Output is correct
9 Correct 53 ms 242644 KB Output is correct
10 Correct 53 ms 242516 KB Output is correct
11 Correct 55 ms 242512 KB Output is correct
12 Correct 52 ms 242512 KB Output is correct
13 Correct 59 ms 242516 KB Output is correct
14 Correct 54 ms 242704 KB Output is correct
15 Correct 55 ms 242516 KB Output is correct
16 Correct 53 ms 242516 KB Output is correct
17 Correct 55 ms 242516 KB Output is correct
18 Correct 54 ms 242508 KB Output is correct
19 Correct 58 ms 242520 KB Output is correct
20 Correct 54 ms 242512 KB Output is correct
21 Correct 54 ms 242516 KB Output is correct
22 Correct 54 ms 242512 KB Output is correct
23 Correct 55 ms 242516 KB Output is correct
24 Correct 53 ms 242520 KB Output is correct
25 Correct 54 ms 242656 KB Output is correct
26 Correct 53 ms 242688 KB Output is correct
27 Correct 55 ms 242612 KB Output is correct
28 Correct 56 ms 242516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 242636 KB Output is correct
2 Correct 53 ms 242516 KB Output is correct
3 Correct 54 ms 242648 KB Output is correct
4 Correct 53 ms 242512 KB Output is correct
5 Correct 55 ms 242500 KB Output is correct
6 Correct 53 ms 242512 KB Output is correct
7 Correct 56 ms 242876 KB Output is correct
8 Correct 58 ms 242712 KB Output is correct
9 Correct 53 ms 242644 KB Output is correct
10 Correct 53 ms 242516 KB Output is correct
11 Correct 55 ms 242512 KB Output is correct
12 Correct 52 ms 242512 KB Output is correct
13 Correct 59 ms 242516 KB Output is correct
14 Correct 54 ms 242704 KB Output is correct
15 Correct 55 ms 242516 KB Output is correct
16 Correct 53 ms 242516 KB Output is correct
17 Correct 55 ms 242516 KB Output is correct
18 Correct 54 ms 242508 KB Output is correct
19 Correct 58 ms 242520 KB Output is correct
20 Correct 54 ms 242512 KB Output is correct
21 Correct 54 ms 242516 KB Output is correct
22 Correct 54 ms 242512 KB Output is correct
23 Correct 55 ms 242516 KB Output is correct
24 Correct 53 ms 242520 KB Output is correct
25 Correct 54 ms 242656 KB Output is correct
26 Correct 53 ms 242688 KB Output is correct
27 Correct 55 ms 242612 KB Output is correct
28 Correct 56 ms 242516 KB Output is correct
29 Correct 54 ms 242660 KB Output is correct
30 Correct 53 ms 242620 KB Output is correct
31 Correct 53 ms 242512 KB Output is correct
32 Correct 55 ms 242516 KB Output is correct
33 Correct 53 ms 242512 KB Output is correct
34 Correct 53 ms 242524 KB Output is correct
35 Correct 55 ms 242512 KB Output is correct
36 Correct 54 ms 242668 KB Output is correct
37 Correct 56 ms 242512 KB Output is correct
38 Correct 55 ms 242600 KB Output is correct
39 Correct 53 ms 242516 KB Output is correct
40 Correct 54 ms 242648 KB Output is correct
41 Correct 54 ms 242512 KB Output is correct
42 Correct 53 ms 242616 KB Output is correct
43 Correct 55 ms 242836 KB Output is correct
44 Correct 54 ms 242632 KB Output is correct
45 Correct 55 ms 242680 KB Output is correct
46 Correct 60 ms 242616 KB Output is correct
47 Correct 60 ms 242668 KB Output is correct
48 Correct 59 ms 242508 KB Output is correct
49 Correct 54 ms 242648 KB Output is correct
50 Correct 53 ms 242516 KB Output is correct
51 Correct 54 ms 242512 KB Output is correct
52 Correct 57 ms 242648 KB Output is correct
53 Correct 54 ms 242516 KB Output is correct
54 Correct 55 ms 242564 KB Output is correct
55 Correct 53 ms 242516 KB Output is correct
56 Correct 56 ms 242492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 430044 KB Output is correct
2 Correct 309 ms 436340 KB Output is correct
3 Correct 275 ms 436688 KB Output is correct
4 Correct 271 ms 435660 KB Output is correct
5 Correct 278 ms 436720 KB Output is correct
6 Correct 273 ms 436944 KB Output is correct
7 Correct 277 ms 436764 KB Output is correct
8 Correct 270 ms 436684 KB Output is correct
9 Correct 268 ms 435660 KB Output is correct
10 Correct 267 ms 436184 KB Output is correct
11 Correct 266 ms 435612 KB Output is correct
12 Correct 267 ms 436128 KB Output is correct
13 Correct 56 ms 242600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 242636 KB Output is correct
2 Correct 53 ms 242516 KB Output is correct
3 Correct 54 ms 242648 KB Output is correct
4 Correct 53 ms 242512 KB Output is correct
5 Correct 55 ms 242500 KB Output is correct
6 Correct 53 ms 242512 KB Output is correct
7 Correct 56 ms 242876 KB Output is correct
8 Correct 58 ms 242712 KB Output is correct
9 Correct 53 ms 242644 KB Output is correct
10 Correct 53 ms 242516 KB Output is correct
11 Correct 55 ms 242512 KB Output is correct
12 Correct 52 ms 242512 KB Output is correct
13 Correct 59 ms 242516 KB Output is correct
14 Correct 54 ms 242704 KB Output is correct
15 Correct 55 ms 242516 KB Output is correct
16 Correct 53 ms 242516 KB Output is correct
17 Correct 55 ms 242516 KB Output is correct
18 Correct 54 ms 242508 KB Output is correct
19 Correct 58 ms 242520 KB Output is correct
20 Correct 54 ms 242512 KB Output is correct
21 Correct 54 ms 242516 KB Output is correct
22 Correct 54 ms 242512 KB Output is correct
23 Correct 55 ms 242516 KB Output is correct
24 Correct 53 ms 242520 KB Output is correct
25 Correct 54 ms 242656 KB Output is correct
26 Correct 53 ms 242688 KB Output is correct
27 Correct 55 ms 242612 KB Output is correct
28 Correct 56 ms 242516 KB Output is correct
29 Correct 54 ms 242660 KB Output is correct
30 Correct 53 ms 242620 KB Output is correct
31 Correct 53 ms 242512 KB Output is correct
32 Correct 55 ms 242516 KB Output is correct
33 Correct 53 ms 242512 KB Output is correct
34 Correct 53 ms 242524 KB Output is correct
35 Correct 55 ms 242512 KB Output is correct
36 Correct 54 ms 242668 KB Output is correct
37 Correct 56 ms 242512 KB Output is correct
38 Correct 55 ms 242600 KB Output is correct
39 Correct 53 ms 242516 KB Output is correct
40 Correct 54 ms 242648 KB Output is correct
41 Correct 54 ms 242512 KB Output is correct
42 Correct 53 ms 242616 KB Output is correct
43 Correct 55 ms 242836 KB Output is correct
44 Correct 54 ms 242632 KB Output is correct
45 Correct 55 ms 242680 KB Output is correct
46 Correct 60 ms 242616 KB Output is correct
47 Correct 60 ms 242668 KB Output is correct
48 Correct 59 ms 242508 KB Output is correct
49 Correct 54 ms 242648 KB Output is correct
50 Correct 53 ms 242516 KB Output is correct
51 Correct 54 ms 242512 KB Output is correct
52 Correct 57 ms 242648 KB Output is correct
53 Correct 54 ms 242516 KB Output is correct
54 Correct 55 ms 242564 KB Output is correct
55 Correct 53 ms 242516 KB Output is correct
56 Correct 56 ms 242492 KB Output is correct
57 Correct 54 ms 242664 KB Output is correct
58 Correct 54 ms 242764 KB Output is correct
59 Correct 54 ms 242660 KB Output is correct
60 Correct 54 ms 242768 KB Output is correct
61 Correct 55 ms 242768 KB Output is correct
62 Correct 54 ms 242784 KB Output is correct
63 Correct 53 ms 242772 KB Output is correct
64 Correct 54 ms 242616 KB Output is correct
65 Correct 56 ms 242772 KB Output is correct
66 Correct 54 ms 242772 KB Output is correct
67 Correct 54 ms 242772 KB Output is correct
68 Correct 55 ms 242780 KB Output is correct
69 Correct 54 ms 242776 KB Output is correct
70 Correct 55 ms 242768 KB Output is correct
71 Correct 56 ms 242640 KB Output is correct
72 Correct 54 ms 242780 KB Output is correct
73 Correct 54 ms 242772 KB Output is correct
74 Correct 54 ms 242776 KB Output is correct
75 Correct 55 ms 242636 KB Output is correct
76 Correct 56 ms 242772 KB Output is correct
77 Correct 54 ms 242556 KB Output is correct
78 Correct 56 ms 243024 KB Output is correct
79 Correct 57 ms 242768 KB Output is correct
80 Correct 59 ms 242676 KB Output is correct
81 Correct 54 ms 242772 KB Output is correct
82 Correct 54 ms 242768 KB Output is correct
83 Correct 55 ms 242772 KB Output is correct
84 Correct 54 ms 242780 KB Output is correct
85 Correct 53 ms 242520 KB Output is correct
86 Correct 56 ms 242512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 242636 KB Output is correct
2 Correct 53 ms 242516 KB Output is correct
3 Correct 54 ms 242648 KB Output is correct
4 Correct 53 ms 242512 KB Output is correct
5 Correct 55 ms 242500 KB Output is correct
6 Correct 53 ms 242512 KB Output is correct
7 Correct 56 ms 242876 KB Output is correct
8 Correct 58 ms 242712 KB Output is correct
9 Correct 53 ms 242644 KB Output is correct
10 Correct 53 ms 242516 KB Output is correct
11 Correct 55 ms 242512 KB Output is correct
12 Correct 52 ms 242512 KB Output is correct
13 Correct 59 ms 242516 KB Output is correct
14 Correct 54 ms 242704 KB Output is correct
15 Correct 55 ms 242516 KB Output is correct
16 Correct 53 ms 242516 KB Output is correct
17 Correct 55 ms 242516 KB Output is correct
18 Correct 54 ms 242508 KB Output is correct
19 Correct 58 ms 242520 KB Output is correct
20 Correct 54 ms 242512 KB Output is correct
21 Correct 54 ms 242516 KB Output is correct
22 Correct 54 ms 242512 KB Output is correct
23 Correct 55 ms 242516 KB Output is correct
24 Correct 53 ms 242520 KB Output is correct
25 Correct 54 ms 242656 KB Output is correct
26 Correct 53 ms 242688 KB Output is correct
27 Correct 55 ms 242612 KB Output is correct
28 Correct 56 ms 242516 KB Output is correct
29 Correct 54 ms 242660 KB Output is correct
30 Correct 53 ms 242620 KB Output is correct
31 Correct 53 ms 242512 KB Output is correct
32 Correct 55 ms 242516 KB Output is correct
33 Correct 53 ms 242512 KB Output is correct
34 Correct 53 ms 242524 KB Output is correct
35 Correct 55 ms 242512 KB Output is correct
36 Correct 54 ms 242668 KB Output is correct
37 Correct 56 ms 242512 KB Output is correct
38 Correct 55 ms 242600 KB Output is correct
39 Correct 53 ms 242516 KB Output is correct
40 Correct 54 ms 242648 KB Output is correct
41 Correct 54 ms 242512 KB Output is correct
42 Correct 53 ms 242616 KB Output is correct
43 Correct 55 ms 242836 KB Output is correct
44 Correct 54 ms 242632 KB Output is correct
45 Correct 55 ms 242680 KB Output is correct
46 Correct 60 ms 242616 KB Output is correct
47 Correct 60 ms 242668 KB Output is correct
48 Correct 59 ms 242508 KB Output is correct
49 Correct 54 ms 242648 KB Output is correct
50 Correct 53 ms 242516 KB Output is correct
51 Correct 54 ms 242512 KB Output is correct
52 Correct 57 ms 242648 KB Output is correct
53 Correct 54 ms 242516 KB Output is correct
54 Correct 55 ms 242564 KB Output is correct
55 Correct 53 ms 242516 KB Output is correct
56 Correct 56 ms 242492 KB Output is correct
57 Correct 304 ms 430044 KB Output is correct
58 Correct 309 ms 436340 KB Output is correct
59 Correct 275 ms 436688 KB Output is correct
60 Correct 271 ms 435660 KB Output is correct
61 Correct 278 ms 436720 KB Output is correct
62 Correct 273 ms 436944 KB Output is correct
63 Correct 277 ms 436764 KB Output is correct
64 Correct 270 ms 436684 KB Output is correct
65 Correct 268 ms 435660 KB Output is correct
66 Correct 267 ms 436184 KB Output is correct
67 Correct 266 ms 435612 KB Output is correct
68 Correct 267 ms 436128 KB Output is correct
69 Correct 56 ms 242600 KB Output is correct
70 Correct 54 ms 242664 KB Output is correct
71 Correct 54 ms 242764 KB Output is correct
72 Correct 54 ms 242660 KB Output is correct
73 Correct 54 ms 242768 KB Output is correct
74 Correct 55 ms 242768 KB Output is correct
75 Correct 54 ms 242784 KB Output is correct
76 Correct 53 ms 242772 KB Output is correct
77 Correct 54 ms 242616 KB Output is correct
78 Correct 56 ms 242772 KB Output is correct
79 Correct 54 ms 242772 KB Output is correct
80 Correct 54 ms 242772 KB Output is correct
81 Correct 55 ms 242780 KB Output is correct
82 Correct 54 ms 242776 KB Output is correct
83 Correct 55 ms 242768 KB Output is correct
84 Correct 56 ms 242640 KB Output is correct
85 Correct 54 ms 242780 KB Output is correct
86 Correct 54 ms 242772 KB Output is correct
87 Correct 54 ms 242776 KB Output is correct
88 Correct 55 ms 242636 KB Output is correct
89 Correct 56 ms 242772 KB Output is correct
90 Correct 54 ms 242556 KB Output is correct
91 Correct 56 ms 243024 KB Output is correct
92 Correct 57 ms 242768 KB Output is correct
93 Correct 59 ms 242676 KB Output is correct
94 Correct 54 ms 242772 KB Output is correct
95 Correct 54 ms 242768 KB Output is correct
96 Correct 55 ms 242772 KB Output is correct
97 Correct 54 ms 242780 KB Output is correct
98 Correct 53 ms 242520 KB Output is correct
99 Correct 56 ms 242512 KB Output is correct
100 Correct 195 ms 357404 KB Output is correct
101 Correct 205 ms 358760 KB Output is correct
102 Correct 207 ms 358096 KB Output is correct
103 Correct 196 ms 357328 KB Output is correct
104 Correct 205 ms 357528 KB Output is correct
105 Correct 245 ms 383796 KB Output is correct
106 Correct 249 ms 383948 KB Output is correct
107 Correct 255 ms 383676 KB Output is correct
108 Correct 245 ms 383636 KB Output is correct
109 Correct 243 ms 383540 KB Output is correct
110 Correct 199 ms 357328 KB Output is correct
111 Correct 205 ms 357424 KB Output is correct
112 Correct 195 ms 357328 KB Output is correct
113 Correct 205 ms 358180 KB Output is correct
114 Correct 199 ms 358612 KB Output is correct
115 Correct 275 ms 435608 KB Output is correct
116 Correct 297 ms 436884 KB Output is correct
117 Correct 267 ms 437128 KB Output is correct
118 Correct 268 ms 435828 KB Output is correct
119 Correct 267 ms 436944 KB Output is correct
120 Correct 205 ms 357540 KB Output is correct
121 Correct 202 ms 357484 KB Output is correct
122 Correct 198 ms 358088 KB Output is correct
123 Correct 199 ms 357512 KB Output is correct
124 Correct 218 ms 396564 KB Output is correct
125 Correct 214 ms 396992 KB Output is correct
126 Correct 211 ms 396984 KB Output is correct
127 Correct 214 ms 397516 KB Output is correct
128 Correct 120 ms 303256 KB Output is correct
129 Correct 121 ms 303228 KB Output is correct
130 Correct 120 ms 303056 KB Output is correct
131 Correct 53 ms 242516 KB Output is correct