Submission #1116332

# Submission time Handle Problem Language Result Execution time Memory
1116332 2024-11-21T14:06:05 Z nikolashami Homework (CEOI22_homework) C++17
100 / 100
158 ms 161268 KB
#include <bits/stdc++.h>
using namespace std;

//?->0
//min->1
//max->2

const int N=4e6+2;
int id=1,n;
string s;

struct range{
	int l,r,sz;
}dp[N];

struct{
	int tp=0,idx;
}lc[N],rc[N];

int r(int i,int node){
	bool desno=0;
	while(i<n){
		if(s[i]=='?'){
			if(!desno){
				lc[node].tp=0;
				lc[node].idx=++id;
				desno=1;
			}else{
				rc[node].tp=0;
				rc[node].idx=++id;
			}
		}
		else if(s[i]=='('){
			if(!desno){
				lc[node].tp=(s[i-1]=='x'?2:1);
				lc[node].idx=++id;
				i=r(i+1,id);
				desno=1;
			}else{
				rc[node].tp=(s[i-1]=='x'?2:1);
				rc[node].idx=++id;
				i=r(i+1,id);
			}
			continue;
		}
		else if(s[i]==')')
			return i+1;
		++i;
	}
	return n-1;
}

void dfs(int node,int stanje){
	range levo,desno;
	if(lc[node].tp){
		dfs(lc[node].idx,lc[node].tp);
		levo=dp[lc[node].idx];
	}else{
		levo.l=levo.r=0;
		levo.sz=1;
	}
	if(rc[node].tp){
		dfs(rc[node].idx,rc[node].tp);
		desno=dp[rc[node].idx];
	}else{
		desno.l=desno.r=0;
		desno.sz=1;
	}
	dp[node].sz=levo.sz+desno.sz;
	if(stanje==1){	
		dp[node].l=min(levo.l,desno.l);
		dp[node].r=levo.r+desno.r;
	}else{
		dp[node].l=levo.l+desno.l+1;
		dp[node].r=max(levo.r+desno.sz,desno.r+levo.sz);
	}
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>s;
	n=s.size();

	r(4,1);
	dfs(1,(s[2]=='x'?2:1));

	cout<<dp[1].r-dp[1].l+1;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 64592 KB Output is correct
2 Correct 11 ms 64480 KB Output is correct
3 Correct 10 ms 64760 KB Output is correct
4 Correct 11 ms 64760 KB Output is correct
5 Correct 11 ms 64692 KB Output is correct
6 Correct 10 ms 64592 KB Output is correct
7 Correct 15 ms 64592 KB Output is correct
8 Correct 12 ms 64680 KB Output is correct
9 Correct 10 ms 64728 KB Output is correct
10 Correct 10 ms 64592 KB Output is correct
11 Correct 12 ms 64592 KB Output is correct
12 Correct 12 ms 64592 KB Output is correct
13 Correct 10 ms 64592 KB Output is correct
14 Correct 10 ms 64592 KB Output is correct
15 Correct 10 ms 64736 KB Output is correct
16 Correct 10 ms 64592 KB Output is correct
17 Correct 11 ms 64592 KB Output is correct
18 Correct 11 ms 64592 KB Output is correct
19 Correct 10 ms 64732 KB Output is correct
20 Correct 10 ms 64592 KB Output is correct
21 Correct 10 ms 64732 KB Output is correct
22 Correct 9 ms 64712 KB Output is correct
23 Correct 11 ms 64592 KB Output is correct
24 Correct 11 ms 64600 KB Output is correct
25 Correct 9 ms 64592 KB Output is correct
26 Correct 9 ms 64604 KB Output is correct
27 Correct 9 ms 64604 KB Output is correct
28 Correct 24 ms 64592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 64592 KB Output is correct
2 Correct 11 ms 64480 KB Output is correct
3 Correct 10 ms 64760 KB Output is correct
4 Correct 11 ms 64760 KB Output is correct
5 Correct 11 ms 64692 KB Output is correct
6 Correct 10 ms 64592 KB Output is correct
7 Correct 15 ms 64592 KB Output is correct
8 Correct 12 ms 64680 KB Output is correct
9 Correct 10 ms 64728 KB Output is correct
10 Correct 10 ms 64592 KB Output is correct
11 Correct 12 ms 64592 KB Output is correct
12 Correct 12 ms 64592 KB Output is correct
13 Correct 10 ms 64592 KB Output is correct
14 Correct 10 ms 64592 KB Output is correct
15 Correct 10 ms 64736 KB Output is correct
16 Correct 10 ms 64592 KB Output is correct
17 Correct 11 ms 64592 KB Output is correct
18 Correct 11 ms 64592 KB Output is correct
19 Correct 10 ms 64732 KB Output is correct
20 Correct 10 ms 64592 KB Output is correct
21 Correct 10 ms 64732 KB Output is correct
22 Correct 9 ms 64712 KB Output is correct
23 Correct 11 ms 64592 KB Output is correct
24 Correct 11 ms 64600 KB Output is correct
25 Correct 9 ms 64592 KB Output is correct
26 Correct 9 ms 64604 KB Output is correct
27 Correct 9 ms 64604 KB Output is correct
28 Correct 24 ms 64592 KB Output is correct
29 Correct 10 ms 64760 KB Output is correct
30 Correct 15 ms 64592 KB Output is correct
31 Correct 11 ms 64592 KB Output is correct
32 Correct 12 ms 64716 KB Output is correct
33 Correct 11 ms 64592 KB Output is correct
34 Correct 17 ms 64592 KB Output is correct
35 Correct 16 ms 64592 KB Output is correct
36 Correct 11 ms 64592 KB Output is correct
37 Correct 9 ms 64592 KB Output is correct
38 Correct 10 ms 64592 KB Output is correct
39 Correct 9 ms 64592 KB Output is correct
40 Correct 9 ms 64592 KB Output is correct
41 Correct 9 ms 64904 KB Output is correct
42 Correct 9 ms 64760 KB Output is correct
43 Correct 10 ms 64756 KB Output is correct
44 Correct 9 ms 64592 KB Output is correct
45 Correct 10 ms 64660 KB Output is correct
46 Correct 10 ms 64592 KB Output is correct
47 Correct 9 ms 64644 KB Output is correct
48 Correct 9 ms 64592 KB Output is correct
49 Correct 10 ms 64592 KB Output is correct
50 Correct 9 ms 64592 KB Output is correct
51 Correct 9 ms 64592 KB Output is correct
52 Correct 12 ms 64684 KB Output is correct
53 Correct 10 ms 64592 KB Output is correct
54 Correct 12 ms 64592 KB Output is correct
55 Correct 11 ms 64592 KB Output is correct
56 Correct 10 ms 64592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 160972 KB Output is correct
2 Correct 130 ms 161108 KB Output is correct
3 Correct 142 ms 160972 KB Output is correct
4 Correct 135 ms 160948 KB Output is correct
5 Correct 135 ms 160980 KB Output is correct
6 Correct 134 ms 161124 KB Output is correct
7 Correct 135 ms 160972 KB Output is correct
8 Correct 141 ms 160976 KB Output is correct
9 Correct 137 ms 161096 KB Output is correct
10 Correct 141 ms 161228 KB Output is correct
11 Correct 136 ms 160972 KB Output is correct
12 Correct 158 ms 160976 KB Output is correct
13 Correct 10 ms 64592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 64592 KB Output is correct
2 Correct 11 ms 64480 KB Output is correct
3 Correct 10 ms 64760 KB Output is correct
4 Correct 11 ms 64760 KB Output is correct
5 Correct 11 ms 64692 KB Output is correct
6 Correct 10 ms 64592 KB Output is correct
7 Correct 15 ms 64592 KB Output is correct
8 Correct 12 ms 64680 KB Output is correct
9 Correct 10 ms 64728 KB Output is correct
10 Correct 10 ms 64592 KB Output is correct
11 Correct 12 ms 64592 KB Output is correct
12 Correct 12 ms 64592 KB Output is correct
13 Correct 10 ms 64592 KB Output is correct
14 Correct 10 ms 64592 KB Output is correct
15 Correct 10 ms 64736 KB Output is correct
16 Correct 10 ms 64592 KB Output is correct
17 Correct 11 ms 64592 KB Output is correct
18 Correct 11 ms 64592 KB Output is correct
19 Correct 10 ms 64732 KB Output is correct
20 Correct 10 ms 64592 KB Output is correct
21 Correct 10 ms 64732 KB Output is correct
22 Correct 9 ms 64712 KB Output is correct
23 Correct 11 ms 64592 KB Output is correct
24 Correct 11 ms 64600 KB Output is correct
25 Correct 9 ms 64592 KB Output is correct
26 Correct 9 ms 64604 KB Output is correct
27 Correct 9 ms 64604 KB Output is correct
28 Correct 24 ms 64592 KB Output is correct
29 Correct 10 ms 64760 KB Output is correct
30 Correct 15 ms 64592 KB Output is correct
31 Correct 11 ms 64592 KB Output is correct
32 Correct 12 ms 64716 KB Output is correct
33 Correct 11 ms 64592 KB Output is correct
34 Correct 17 ms 64592 KB Output is correct
35 Correct 16 ms 64592 KB Output is correct
36 Correct 11 ms 64592 KB Output is correct
37 Correct 9 ms 64592 KB Output is correct
38 Correct 10 ms 64592 KB Output is correct
39 Correct 9 ms 64592 KB Output is correct
40 Correct 9 ms 64592 KB Output is correct
41 Correct 9 ms 64904 KB Output is correct
42 Correct 9 ms 64760 KB Output is correct
43 Correct 10 ms 64756 KB Output is correct
44 Correct 9 ms 64592 KB Output is correct
45 Correct 10 ms 64660 KB Output is correct
46 Correct 10 ms 64592 KB Output is correct
47 Correct 9 ms 64644 KB Output is correct
48 Correct 9 ms 64592 KB Output is correct
49 Correct 10 ms 64592 KB Output is correct
50 Correct 9 ms 64592 KB Output is correct
51 Correct 9 ms 64592 KB Output is correct
52 Correct 12 ms 64684 KB Output is correct
53 Correct 10 ms 64592 KB Output is correct
54 Correct 12 ms 64592 KB Output is correct
55 Correct 11 ms 64592 KB Output is correct
56 Correct 10 ms 64592 KB Output is correct
57 Correct 11 ms 64592 KB Output is correct
58 Correct 10 ms 64592 KB Output is correct
59 Correct 9 ms 64652 KB Output is correct
60 Correct 13 ms 64740 KB Output is correct
61 Correct 15 ms 64592 KB Output is correct
62 Correct 15 ms 64592 KB Output is correct
63 Correct 17 ms 64592 KB Output is correct
64 Correct 18 ms 64592 KB Output is correct
65 Correct 12 ms 64592 KB Output is correct
66 Correct 11 ms 64592 KB Output is correct
67 Correct 10 ms 64592 KB Output is correct
68 Correct 12 ms 64848 KB Output is correct
69 Correct 11 ms 64688 KB Output is correct
70 Correct 10 ms 64592 KB Output is correct
71 Correct 10 ms 64592 KB Output is correct
72 Correct 10 ms 64688 KB Output is correct
73 Correct 10 ms 64592 KB Output is correct
74 Correct 10 ms 64592 KB Output is correct
75 Correct 10 ms 64592 KB Output is correct
76 Correct 10 ms 64592 KB Output is correct
77 Correct 10 ms 64592 KB Output is correct
78 Correct 15 ms 64592 KB Output is correct
79 Correct 11 ms 64592 KB Output is correct
80 Correct 10 ms 64592 KB Output is correct
81 Correct 10 ms 64592 KB Output is correct
82 Correct 10 ms 64592 KB Output is correct
83 Correct 10 ms 64744 KB Output is correct
84 Correct 10 ms 64592 KB Output is correct
85 Correct 11 ms 64592 KB Output is correct
86 Correct 9 ms 64720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 64592 KB Output is correct
2 Correct 11 ms 64480 KB Output is correct
3 Correct 10 ms 64760 KB Output is correct
4 Correct 11 ms 64760 KB Output is correct
5 Correct 11 ms 64692 KB Output is correct
6 Correct 10 ms 64592 KB Output is correct
7 Correct 15 ms 64592 KB Output is correct
8 Correct 12 ms 64680 KB Output is correct
9 Correct 10 ms 64728 KB Output is correct
10 Correct 10 ms 64592 KB Output is correct
11 Correct 12 ms 64592 KB Output is correct
12 Correct 12 ms 64592 KB Output is correct
13 Correct 10 ms 64592 KB Output is correct
14 Correct 10 ms 64592 KB Output is correct
15 Correct 10 ms 64736 KB Output is correct
16 Correct 10 ms 64592 KB Output is correct
17 Correct 11 ms 64592 KB Output is correct
18 Correct 11 ms 64592 KB Output is correct
19 Correct 10 ms 64732 KB Output is correct
20 Correct 10 ms 64592 KB Output is correct
21 Correct 10 ms 64732 KB Output is correct
22 Correct 9 ms 64712 KB Output is correct
23 Correct 11 ms 64592 KB Output is correct
24 Correct 11 ms 64600 KB Output is correct
25 Correct 9 ms 64592 KB Output is correct
26 Correct 9 ms 64604 KB Output is correct
27 Correct 9 ms 64604 KB Output is correct
28 Correct 24 ms 64592 KB Output is correct
29 Correct 10 ms 64760 KB Output is correct
30 Correct 15 ms 64592 KB Output is correct
31 Correct 11 ms 64592 KB Output is correct
32 Correct 12 ms 64716 KB Output is correct
33 Correct 11 ms 64592 KB Output is correct
34 Correct 17 ms 64592 KB Output is correct
35 Correct 16 ms 64592 KB Output is correct
36 Correct 11 ms 64592 KB Output is correct
37 Correct 9 ms 64592 KB Output is correct
38 Correct 10 ms 64592 KB Output is correct
39 Correct 9 ms 64592 KB Output is correct
40 Correct 9 ms 64592 KB Output is correct
41 Correct 9 ms 64904 KB Output is correct
42 Correct 9 ms 64760 KB Output is correct
43 Correct 10 ms 64756 KB Output is correct
44 Correct 9 ms 64592 KB Output is correct
45 Correct 10 ms 64660 KB Output is correct
46 Correct 10 ms 64592 KB Output is correct
47 Correct 9 ms 64644 KB Output is correct
48 Correct 9 ms 64592 KB Output is correct
49 Correct 10 ms 64592 KB Output is correct
50 Correct 9 ms 64592 KB Output is correct
51 Correct 9 ms 64592 KB Output is correct
52 Correct 12 ms 64684 KB Output is correct
53 Correct 10 ms 64592 KB Output is correct
54 Correct 12 ms 64592 KB Output is correct
55 Correct 11 ms 64592 KB Output is correct
56 Correct 10 ms 64592 KB Output is correct
57 Correct 137 ms 160972 KB Output is correct
58 Correct 130 ms 161108 KB Output is correct
59 Correct 142 ms 160972 KB Output is correct
60 Correct 135 ms 160948 KB Output is correct
61 Correct 135 ms 160980 KB Output is correct
62 Correct 134 ms 161124 KB Output is correct
63 Correct 135 ms 160972 KB Output is correct
64 Correct 141 ms 160976 KB Output is correct
65 Correct 137 ms 161096 KB Output is correct
66 Correct 141 ms 161228 KB Output is correct
67 Correct 136 ms 160972 KB Output is correct
68 Correct 158 ms 160976 KB Output is correct
69 Correct 10 ms 64592 KB Output is correct
70 Correct 11 ms 64592 KB Output is correct
71 Correct 10 ms 64592 KB Output is correct
72 Correct 9 ms 64652 KB Output is correct
73 Correct 13 ms 64740 KB Output is correct
74 Correct 15 ms 64592 KB Output is correct
75 Correct 15 ms 64592 KB Output is correct
76 Correct 17 ms 64592 KB Output is correct
77 Correct 18 ms 64592 KB Output is correct
78 Correct 12 ms 64592 KB Output is correct
79 Correct 11 ms 64592 KB Output is correct
80 Correct 10 ms 64592 KB Output is correct
81 Correct 12 ms 64848 KB Output is correct
82 Correct 11 ms 64688 KB Output is correct
83 Correct 10 ms 64592 KB Output is correct
84 Correct 10 ms 64592 KB Output is correct
85 Correct 10 ms 64688 KB Output is correct
86 Correct 10 ms 64592 KB Output is correct
87 Correct 10 ms 64592 KB Output is correct
88 Correct 10 ms 64592 KB Output is correct
89 Correct 10 ms 64592 KB Output is correct
90 Correct 10 ms 64592 KB Output is correct
91 Correct 15 ms 64592 KB Output is correct
92 Correct 11 ms 64592 KB Output is correct
93 Correct 10 ms 64592 KB Output is correct
94 Correct 10 ms 64592 KB Output is correct
95 Correct 10 ms 64592 KB Output is correct
96 Correct 10 ms 64744 KB Output is correct
97 Correct 10 ms 64592 KB Output is correct
98 Correct 11 ms 64592 KB Output is correct
99 Correct 9 ms 64720 KB Output is correct
100 Correct 71 ms 101980 KB Output is correct
101 Correct 62 ms 103252 KB Output is correct
102 Correct 56 ms 103372 KB Output is correct
103 Correct 59 ms 103372 KB Output is correct
104 Correct 54 ms 103224 KB Output is correct
105 Correct 89 ms 124108 KB Output is correct
106 Correct 83 ms 124256 KB Output is correct
107 Correct 81 ms 124076 KB Output is correct
108 Correct 78 ms 124208 KB Output is correct
109 Correct 79 ms 124112 KB Output is correct
110 Correct 68 ms 103248 KB Output is correct
111 Correct 64 ms 103628 KB Output is correct
112 Correct 68 ms 103376 KB Output is correct
113 Correct 66 ms 103224 KB Output is correct
114 Correct 76 ms 103252 KB Output is correct
115 Correct 131 ms 161072 KB Output is correct
116 Correct 142 ms 161076 KB Output is correct
117 Correct 141 ms 161228 KB Output is correct
118 Correct 141 ms 161096 KB Output is correct
119 Correct 138 ms 161268 KB Output is correct
120 Correct 60 ms 103252 KB Output is correct
121 Correct 67 ms 103492 KB Output is correct
122 Correct 63 ms 103372 KB Output is correct
123 Correct 70 ms 103368 KB Output is correct
124 Correct 106 ms 134860 KB Output is correct
125 Correct 93 ms 135884 KB Output is correct
126 Correct 96 ms 135116 KB Output is correct
127 Correct 96 ms 135892 KB Output is correct
128 Correct 29 ms 84944 KB Output is correct
129 Correct 27 ms 84940 KB Output is correct
130 Correct 26 ms 84944 KB Output is correct
131 Correct 11 ms 64592 KB Output is correct