답안 #936456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936456 2024-03-01T21:39:01 Z Edu175 Homework (CEOI22_homework) C++17
100 / 100
179 ms 116776 KB
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ceoi=b;i<ceoi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto kdjfhg:v)cout<<kdjfhg<<" ";cout<<"\n"
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=2e6+5;
ll L[MAXN],R[MAXN];
ll t[MAXN];
ll cnt=0, pos=0,q=0;
string s;
ll parse(){
	//cout<<"parse "<<pos<<endl;
	ll x=cnt++;
	if(s[pos]=='?'){
		q++;
		pos++;
		return x;
	}
	t[x]=(s[pos+2]=='x');
	pos+=4;
	L[x]=parse();
	//comma
	pos++;
	R[x]=parse();
	//)
	pos++;
	return x;
}
ii dp[MAXN];
ll sum[MAXN];
int main(){
	cin>>s;
	parse();
	ll n=cnt;
	/*fore(i,0,n){
		cout<<i<<" ("<<t[i]<<"): "<<g[i].fst<<","<<g[i].snd<<"\n";
	}*/
	for(ll x=n-1;x>=0;x--){
		ii &res=dp[x];
		if(!L[x]){
			res={0,0};
			sum[x]=1;
			continue;
		}
		auto [l1,r1]=dp[L[x]];
		auto [l2,r2]=dp[R[x]];
		ll n1=sum[L[x]],n2=sum[R[x]];
		if(t[x]){
			l1=n1-1-l1,r1=n1-1-r1;
			swap(l1,r1);
			l2=n2-1-l2,r2=n2-1-r2;
			swap(l2,r2);
		}
		auto &[l,r]=dp[x];
		l=min(l1,l2);
		r=r1+r2;
		sum[x]=n1+n2;
		if(t[x]){
			l=sum[x]-1-l,r=sum[x]-1-r;
			swap(l,r);
		}
		//cout<<x<<": "<<l<<","<<r<<"\n";
	}
	cout<<dp[0].snd-dp[0].fst+1<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8628 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8652 KB Output is correct
9 Correct 1 ms 8548 KB Output is correct
10 Correct 1 ms 8552 KB Output is correct
11 Correct 1 ms 8552 KB Output is correct
12 Correct 1 ms 8552 KB Output is correct
13 Correct 1 ms 8552 KB Output is correct
14 Correct 2 ms 8696 KB Output is correct
15 Correct 2 ms 8552 KB Output is correct
16 Correct 1 ms 8552 KB Output is correct
17 Correct 2 ms 8552 KB Output is correct
18 Correct 1 ms 8552 KB Output is correct
19 Correct 1 ms 8552 KB Output is correct
20 Correct 1 ms 8552 KB Output is correct
21 Correct 1 ms 8552 KB Output is correct
22 Correct 3 ms 8552 KB Output is correct
23 Correct 1 ms 8552 KB Output is correct
24 Correct 1 ms 8552 KB Output is correct
25 Correct 1 ms 8552 KB Output is correct
26 Correct 1 ms 8552 KB Output is correct
27 Correct 1 ms 8552 KB Output is correct
28 Correct 1 ms 8552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8628 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8652 KB Output is correct
9 Correct 1 ms 8548 KB Output is correct
10 Correct 1 ms 8552 KB Output is correct
11 Correct 1 ms 8552 KB Output is correct
12 Correct 1 ms 8552 KB Output is correct
13 Correct 1 ms 8552 KB Output is correct
14 Correct 2 ms 8696 KB Output is correct
15 Correct 2 ms 8552 KB Output is correct
16 Correct 1 ms 8552 KB Output is correct
17 Correct 2 ms 8552 KB Output is correct
18 Correct 1 ms 8552 KB Output is correct
19 Correct 1 ms 8552 KB Output is correct
20 Correct 1 ms 8552 KB Output is correct
21 Correct 1 ms 8552 KB Output is correct
22 Correct 3 ms 8552 KB Output is correct
23 Correct 1 ms 8552 KB Output is correct
24 Correct 1 ms 8552 KB Output is correct
25 Correct 1 ms 8552 KB Output is correct
26 Correct 1 ms 8552 KB Output is correct
27 Correct 1 ms 8552 KB Output is correct
28 Correct 1 ms 8552 KB Output is correct
29 Correct 2 ms 8548 KB Output is correct
30 Correct 2 ms 8552 KB Output is correct
31 Correct 1 ms 8552 KB Output is correct
32 Correct 2 ms 8552 KB Output is correct
33 Correct 2 ms 8552 KB Output is correct
34 Correct 1 ms 8652 KB Output is correct
35 Correct 1 ms 8552 KB Output is correct
36 Correct 2 ms 8552 KB Output is correct
37 Correct 1 ms 8552 KB Output is correct
38 Correct 1 ms 8552 KB Output is correct
39 Correct 1 ms 8556 KB Output is correct
40 Correct 2 ms 8552 KB Output is correct
41 Correct 1 ms 8552 KB Output is correct
42 Correct 1 ms 8552 KB Output is correct
43 Correct 1 ms 8552 KB Output is correct
44 Correct 1 ms 8552 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 2 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 2 ms 8552 KB Output is correct
52 Correct 1 ms 8552 KB Output is correct
53 Correct 2 ms 8552 KB Output is correct
54 Correct 2 ms 8560 KB Output is correct
55 Correct 1 ms 8552 KB Output is correct
56 Correct 2 ms 8552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 116268 KB Output is correct
2 Correct 147 ms 116776 KB Output is correct
3 Correct 150 ms 116160 KB Output is correct
4 Correct 153 ms 116416 KB Output is correct
5 Correct 153 ms 116160 KB Output is correct
6 Correct 147 ms 116408 KB Output is correct
7 Correct 179 ms 116160 KB Output is correct
8 Correct 148 ms 116676 KB Output is correct
9 Correct 154 ms 116356 KB Output is correct
10 Correct 145 ms 116144 KB Output is correct
11 Correct 144 ms 116172 KB Output is correct
12 Correct 158 ms 116216 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8628 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8652 KB Output is correct
9 Correct 1 ms 8548 KB Output is correct
10 Correct 1 ms 8552 KB Output is correct
11 Correct 1 ms 8552 KB Output is correct
12 Correct 1 ms 8552 KB Output is correct
13 Correct 1 ms 8552 KB Output is correct
14 Correct 2 ms 8696 KB Output is correct
15 Correct 2 ms 8552 KB Output is correct
16 Correct 1 ms 8552 KB Output is correct
17 Correct 2 ms 8552 KB Output is correct
18 Correct 1 ms 8552 KB Output is correct
19 Correct 1 ms 8552 KB Output is correct
20 Correct 1 ms 8552 KB Output is correct
21 Correct 1 ms 8552 KB Output is correct
22 Correct 3 ms 8552 KB Output is correct
23 Correct 1 ms 8552 KB Output is correct
24 Correct 1 ms 8552 KB Output is correct
25 Correct 1 ms 8552 KB Output is correct
26 Correct 1 ms 8552 KB Output is correct
27 Correct 1 ms 8552 KB Output is correct
28 Correct 1 ms 8552 KB Output is correct
29 Correct 2 ms 8548 KB Output is correct
30 Correct 2 ms 8552 KB Output is correct
31 Correct 1 ms 8552 KB Output is correct
32 Correct 2 ms 8552 KB Output is correct
33 Correct 2 ms 8552 KB Output is correct
34 Correct 1 ms 8652 KB Output is correct
35 Correct 1 ms 8552 KB Output is correct
36 Correct 2 ms 8552 KB Output is correct
37 Correct 1 ms 8552 KB Output is correct
38 Correct 1 ms 8552 KB Output is correct
39 Correct 1 ms 8556 KB Output is correct
40 Correct 2 ms 8552 KB Output is correct
41 Correct 1 ms 8552 KB Output is correct
42 Correct 1 ms 8552 KB Output is correct
43 Correct 1 ms 8552 KB Output is correct
44 Correct 1 ms 8552 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 2 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 2 ms 8552 KB Output is correct
52 Correct 1 ms 8552 KB Output is correct
53 Correct 2 ms 8552 KB Output is correct
54 Correct 2 ms 8560 KB Output is correct
55 Correct 1 ms 8552 KB Output is correct
56 Correct 2 ms 8552 KB Output is correct
57 Correct 1 ms 8540 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 1 ms 8540 KB Output is correct
60 Correct 1 ms 8644 KB Output is correct
61 Correct 1 ms 8540 KB Output is correct
62 Correct 1 ms 8540 KB Output is correct
63 Correct 1 ms 8540 KB Output is correct
64 Correct 1 ms 8540 KB Output is correct
65 Correct 2 ms 8540 KB Output is correct
66 Correct 1 ms 8540 KB Output is correct
67 Correct 1 ms 8540 KB Output is correct
68 Correct 1 ms 8536 KB Output is correct
69 Correct 1 ms 8540 KB Output is correct
70 Correct 1 ms 8540 KB Output is correct
71 Correct 2 ms 8676 KB Output is correct
72 Correct 1 ms 8540 KB Output is correct
73 Correct 1 ms 8540 KB Output is correct
74 Correct 2 ms 8540 KB Output is correct
75 Correct 1 ms 8540 KB Output is correct
76 Correct 2 ms 8540 KB Output is correct
77 Correct 1 ms 8644 KB Output is correct
78 Correct 2 ms 8540 KB Output is correct
79 Correct 1 ms 8540 KB Output is correct
80 Correct 1 ms 8640 KB Output is correct
81 Correct 2 ms 8540 KB Output is correct
82 Correct 2 ms 8540 KB Output is correct
83 Correct 1 ms 8640 KB Output is correct
84 Correct 1 ms 8540 KB Output is correct
85 Correct 1 ms 8540 KB Output is correct
86 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8628 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8652 KB Output is correct
9 Correct 1 ms 8548 KB Output is correct
10 Correct 1 ms 8552 KB Output is correct
11 Correct 1 ms 8552 KB Output is correct
12 Correct 1 ms 8552 KB Output is correct
13 Correct 1 ms 8552 KB Output is correct
14 Correct 2 ms 8696 KB Output is correct
15 Correct 2 ms 8552 KB Output is correct
16 Correct 1 ms 8552 KB Output is correct
17 Correct 2 ms 8552 KB Output is correct
18 Correct 1 ms 8552 KB Output is correct
19 Correct 1 ms 8552 KB Output is correct
20 Correct 1 ms 8552 KB Output is correct
21 Correct 1 ms 8552 KB Output is correct
22 Correct 3 ms 8552 KB Output is correct
23 Correct 1 ms 8552 KB Output is correct
24 Correct 1 ms 8552 KB Output is correct
25 Correct 1 ms 8552 KB Output is correct
26 Correct 1 ms 8552 KB Output is correct
27 Correct 1 ms 8552 KB Output is correct
28 Correct 1 ms 8552 KB Output is correct
29 Correct 2 ms 8548 KB Output is correct
30 Correct 2 ms 8552 KB Output is correct
31 Correct 1 ms 8552 KB Output is correct
32 Correct 2 ms 8552 KB Output is correct
33 Correct 2 ms 8552 KB Output is correct
34 Correct 1 ms 8652 KB Output is correct
35 Correct 1 ms 8552 KB Output is correct
36 Correct 2 ms 8552 KB Output is correct
37 Correct 1 ms 8552 KB Output is correct
38 Correct 1 ms 8552 KB Output is correct
39 Correct 1 ms 8556 KB Output is correct
40 Correct 2 ms 8552 KB Output is correct
41 Correct 1 ms 8552 KB Output is correct
42 Correct 1 ms 8552 KB Output is correct
43 Correct 1 ms 8552 KB Output is correct
44 Correct 1 ms 8552 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 2 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 2 ms 8552 KB Output is correct
52 Correct 1 ms 8552 KB Output is correct
53 Correct 2 ms 8552 KB Output is correct
54 Correct 2 ms 8560 KB Output is correct
55 Correct 1 ms 8552 KB Output is correct
56 Correct 2 ms 8552 KB Output is correct
57 Correct 150 ms 116268 KB Output is correct
58 Correct 147 ms 116776 KB Output is correct
59 Correct 150 ms 116160 KB Output is correct
60 Correct 153 ms 116416 KB Output is correct
61 Correct 153 ms 116160 KB Output is correct
62 Correct 147 ms 116408 KB Output is correct
63 Correct 179 ms 116160 KB Output is correct
64 Correct 148 ms 116676 KB Output is correct
65 Correct 154 ms 116356 KB Output is correct
66 Correct 145 ms 116144 KB Output is correct
67 Correct 144 ms 116172 KB Output is correct
68 Correct 158 ms 116216 KB Output is correct
69 Correct 1 ms 8540 KB Output is correct
70 Correct 1 ms 8540 KB Output is correct
71 Correct 2 ms 8540 KB Output is correct
72 Correct 1 ms 8540 KB Output is correct
73 Correct 1 ms 8644 KB Output is correct
74 Correct 1 ms 8540 KB Output is correct
75 Correct 1 ms 8540 KB Output is correct
76 Correct 1 ms 8540 KB Output is correct
77 Correct 1 ms 8540 KB Output is correct
78 Correct 2 ms 8540 KB Output is correct
79 Correct 1 ms 8540 KB Output is correct
80 Correct 1 ms 8540 KB Output is correct
81 Correct 1 ms 8536 KB Output is correct
82 Correct 1 ms 8540 KB Output is correct
83 Correct 1 ms 8540 KB Output is correct
84 Correct 2 ms 8676 KB Output is correct
85 Correct 1 ms 8540 KB Output is correct
86 Correct 1 ms 8540 KB Output is correct
87 Correct 2 ms 8540 KB Output is correct
88 Correct 1 ms 8540 KB Output is correct
89 Correct 2 ms 8540 KB Output is correct
90 Correct 1 ms 8644 KB Output is correct
91 Correct 2 ms 8540 KB Output is correct
92 Correct 1 ms 8540 KB Output is correct
93 Correct 1 ms 8640 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 1 ms 8640 KB Output is correct
97 Correct 1 ms 8540 KB Output is correct
98 Correct 1 ms 8540 KB Output is correct
99 Correct 1 ms 8540 KB Output is correct
100 Correct 138 ms 108216 KB Output is correct
101 Correct 139 ms 107956 KB Output is correct
102 Correct 135 ms 107932 KB Output is correct
103 Correct 139 ms 108056 KB Output is correct
104 Correct 135 ms 107956 KB Output is correct
105 Correct 145 ms 113592 KB Output is correct
106 Correct 147 ms 113416 KB Output is correct
107 Correct 141 ms 113152 KB Output is correct
108 Correct 141 ms 113916 KB Output is correct
109 Correct 142 ms 113188 KB Output is correct
110 Correct 148 ms 108444 KB Output is correct
111 Correct 167 ms 108152 KB Output is correct
112 Correct 141 ms 108148 KB Output is correct
113 Correct 140 ms 108168 KB Output is correct
114 Correct 161 ms 108284 KB Output is correct
115 Correct 149 ms 116448 KB Output is correct
116 Correct 146 ms 116664 KB Output is correct
117 Correct 146 ms 116724 KB Output is correct
118 Correct 149 ms 116100 KB Output is correct
119 Correct 143 ms 116188 KB Output is correct
120 Correct 138 ms 108920 KB Output is correct
121 Correct 140 ms 107956 KB Output is correct
122 Correct 152 ms 108052 KB Output is correct
123 Correct 141 ms 108048 KB Output is correct
124 Correct 142 ms 115884 KB Output is correct
125 Correct 139 ms 115892 KB Output is correct
126 Correct 141 ms 115796 KB Output is correct
127 Correct 139 ms 115892 KB Output is correct
128 Correct 66 ms 65424 KB Output is correct
129 Correct 63 ms 65196 KB Output is correct
130 Correct 64 ms 65124 KB Output is correct
131 Correct 1 ms 8540 KB Output is correct