답안 #796170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796170 2023-07-28T07:19:24 Z amirhoseinfar1385 Homework (CEOI22_homework) C++17
100 / 100
166 ms 149436 KB
#include<bits/stdc++.h>
using namespace std;
string s;
struct dade{
	int c,r,n,ted,tl,tr;
	dade(){
		c=r=n=-1;
		tl=tr=ted=0;
	}
};

const int maxm=7000000+10;
int mid[maxm],sz;
vector<dade>allt;

void cals(){
	vector<int>v;
	for(int i=0;i<sz;i++){
		if(s[i]=='('){
			v.push_back(i);
			continue;
		}
		if(s[i]==')'){
			v.pop_back();
			continue;
		}
		if(s[i]==','){
			mid[v.back()]=i;
			continue;
		}
	}	
}
dade d;

int createtree(int l,int r){
	allt.push_back(d);
	int w=(int)allt.size()-1;
	if(l==r){
		allt[w].n=0;
		return w;
	}
	if(s[l+1]=='a'){
		allt[w].n=2;
	}
	else{
		allt[w].n=1;
	}
	allt[w].c=createtree(l+4,mid[l+3]-1);
	allt[w].r=createtree(mid[l+3]+1,r-1);
	return w;
}

void solve(int i){
	if(allt[i].n==0){
		allt[i].ted=1;
		allt[i].tl=allt[i].tr=1;
		return ;
	}
	int c=allt[i].c,r=allt[i].r;
	solve(c);
	solve(r);
	allt[i].ted=allt[c].ted+allt[r].ted;
	if(allt[i].n==1){
		allt[i].tl=min(allt[c].tl,allt[r].tl);
		allt[i].tr=allt[i].ted-(allt[r].ted-allt[r].tr)-(allt[c].ted-allt[c].tr)-1;
	}
	else{
		allt[i].tr=allt[i].ted-min(allt[c].ted-allt[c].tr,allt[r].ted-allt[r].tr);
		allt[i].tl=allt[r].tl+allt[c].tl;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	sz=(int)s.size();
	cals();
	createtree(0,sz-1);
	solve(0);
	int res=allt[0].tr-allt[0].tl+1;
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 328 KB Output is correct
21 Correct 0 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 328 KB Output is correct
21 Correct 0 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 324 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 328 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 149268 KB Output is correct
2 Correct 155 ms 149288 KB Output is correct
3 Correct 161 ms 149212 KB Output is correct
4 Correct 155 ms 149328 KB Output is correct
5 Correct 166 ms 149436 KB Output is correct
6 Correct 155 ms 149228 KB Output is correct
7 Correct 164 ms 149208 KB Output is correct
8 Correct 159 ms 149284 KB Output is correct
9 Correct 157 ms 149252 KB Output is correct
10 Correct 155 ms 149396 KB Output is correct
11 Correct 146 ms 149268 KB Output is correct
12 Correct 159 ms 149364 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 328 KB Output is correct
21 Correct 0 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 324 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 328 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 484 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 1 ms 460 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 0 ms 460 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 456 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 0 ms 340 KB Output is correct
78 Correct 0 ms 468 KB Output is correct
79 Correct 0 ms 468 KB Output is correct
80 Correct 0 ms 456 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 328 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 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 0 ms 212 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 328 KB Output is correct
21 Correct 0 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 324 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 328 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 157 ms 149268 KB Output is correct
58 Correct 155 ms 149288 KB Output is correct
59 Correct 161 ms 149212 KB Output is correct
60 Correct 155 ms 149328 KB Output is correct
61 Correct 166 ms 149436 KB Output is correct
62 Correct 155 ms 149228 KB Output is correct
63 Correct 164 ms 149208 KB Output is correct
64 Correct 159 ms 149284 KB Output is correct
65 Correct 157 ms 149252 KB Output is correct
66 Correct 155 ms 149396 KB Output is correct
67 Correct 146 ms 149268 KB Output is correct
68 Correct 159 ms 149364 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 484 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 460 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 0 ms 460 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 456 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 0 ms 340 KB Output is correct
91 Correct 0 ms 468 KB Output is correct
92 Correct 0 ms 468 KB Output is correct
93 Correct 0 ms 456 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 328 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 118 ms 96780 KB Output is correct
101 Correct 111 ms 96796 KB Output is correct
102 Correct 105 ms 96828 KB Output is correct
103 Correct 108 ms 96796 KB Output is correct
104 Correct 119 ms 96824 KB Output is correct
105 Correct 161 ms 115656 KB Output is correct
106 Correct 139 ms 115628 KB Output is correct
107 Correct 130 ms 115592 KB Output is correct
108 Correct 149 ms 115492 KB Output is correct
109 Correct 130 ms 115584 KB Output is correct
110 Correct 118 ms 96836 KB Output is correct
111 Correct 114 ms 96828 KB Output is correct
112 Correct 114 ms 96796 KB Output is correct
113 Correct 117 ms 96796 KB Output is correct
114 Correct 115 ms 96816 KB Output is correct
115 Correct 161 ms 149236 KB Output is correct
116 Correct 161 ms 149304 KB Output is correct
117 Correct 158 ms 149304 KB Output is correct
118 Correct 158 ms 149240 KB Output is correct
119 Correct 156 ms 149328 KB Output is correct
120 Correct 109 ms 96784 KB Output is correct
121 Correct 107 ms 96816 KB Output is correct
122 Correct 116 ms 96884 KB Output is correct
123 Correct 123 ms 96804 KB Output is correct
124 Correct 123 ms 126096 KB Output is correct
125 Correct 119 ms 126104 KB Output is correct
126 Correct 121 ms 126204 KB Output is correct
127 Correct 116 ms 126084 KB Output is correct
128 Correct 53 ms 49580 KB Output is correct
129 Correct 47 ms 49548 KB Output is correct
130 Correct 47 ms 49600 KB Output is correct
131 Correct 1 ms 212 KB Output is correct