Submission #837676

# Submission time Handle Problem Language Result Execution time Memory
837676 2023-08-25T14:03:14 Z MohamedAhmed04 Homework (CEOI22_homework) C++14
100 / 100
125 ms 145364 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 4e6 + 10 ;

string s ;

int sz[MAX] , mark[MAX] ;
int L[MAX] , R[MAX] ;
int Lchild[MAX] , Rchild[MAX] ;

int val[MAX] ;

void dfs(int node)
{
	if(mark[node])
	{
		sz[node] = 1 ;
		L[node] = R[node] = 1 ;
		return ;
	}
	int x = Lchild[node] , y = Rchild[node] ;
	dfs(x) , dfs(y) ;
	sz[node] = sz[x] + sz[y] ;
	if(val[node]) //Max
		L[node] = L[x] + L[y] , R[node] = max(sz[x] + R[y] , sz[y] + R[x]) ;
	else
		L[node] = min(L[x] , L[y]) , R[node] = R[x] + R[y] - 1 ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>s ;
	stack<int>st ;
	int cur = 0 ;
	for(int i = 0 ; i < s.size() ; ++i)
	{
		if(s[i] == '(')
		{
			++cur ;
			if(st.size())
			{
				if(!Lchild[st.top()])
					Lchild[st.top()] = cur ;
				else
					Rchild[st.top()] = cur ;
			}
			st.push(cur) ;
			val[cur] = (s[i-1] == 'x') ; //Max
		}
		else if(s[i] == ')')
			st.pop() ;
		else if(s[i] == '?')
		{
			++cur ;
			mark[cur] = 1 ;
			if(!Lchild[st.top()])
				Lchild[st.top()] = cur ;
			else
				Rchild[st.top()] = cur ;
		}
	}
	dfs(1) ;
	return cout<<R[1] - L[1] + 1<<"\n" , 0 ;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0 ; i < s.size() ; ++i)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 138404 KB Output is correct
2 Correct 119 ms 145328 KB Output is correct
3 Correct 125 ms 145256 KB Output is correct
4 Correct 114 ms 145364 KB Output is correct
5 Correct 105 ms 145332 KB Output is correct
6 Correct 106 ms 145312 KB Output is correct
7 Correct 112 ms 145316 KB Output is correct
8 Correct 116 ms 145320 KB Output is correct
9 Correct 103 ms 145324 KB Output is correct
10 Correct 102 ms 145320 KB Output is correct
11 Correct 119 ms 145252 KB Output is correct
12 Correct 116 ms 145316 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 0 ms 340 KB Output is correct
69 Correct 0 ms 340 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 0 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 0 ms 468 KB Output is correct
77 Correct 0 ms 340 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 0 ms 340 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 0 ms 468 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 102 ms 138404 KB Output is correct
58 Correct 119 ms 145328 KB Output is correct
59 Correct 125 ms 145256 KB Output is correct
60 Correct 114 ms 145364 KB Output is correct
61 Correct 105 ms 145332 KB Output is correct
62 Correct 106 ms 145312 KB Output is correct
63 Correct 112 ms 145316 KB Output is correct
64 Correct 116 ms 145320 KB Output is correct
65 Correct 103 ms 145324 KB Output is correct
66 Correct 102 ms 145320 KB Output is correct
67 Correct 119 ms 145252 KB Output is correct
68 Correct 116 ms 145316 KB Output is correct
69 Correct 0 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 340 KB Output is correct
74 Correct 0 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 0 ms 340 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 0 ms 340 KB Output is correct
81 Correct 0 ms 340 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 0 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 0 ms 468 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 0 ms 468 KB Output is correct
90 Correct 0 ms 340 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 0 ms 340 KB Output is correct
94 Correct 1 ms 468 KB Output is correct
95 Correct 0 ms 468 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 0 ms 340 KB Output is correct
99 Correct 0 ms 340 KB Output is correct
100 Correct 62 ms 68952 KB Output is correct
101 Correct 62 ms 68916 KB Output is correct
102 Correct 59 ms 68932 KB Output is correct
103 Correct 71 ms 69036 KB Output is correct
104 Correct 63 ms 68876 KB Output is correct
105 Correct 84 ms 96340 KB Output is correct
106 Correct 83 ms 96260 KB Output is correct
107 Correct 80 ms 96196 KB Output is correct
108 Correct 80 ms 96168 KB Output is correct
109 Correct 81 ms 96296 KB Output is correct
110 Correct 70 ms 68892 KB Output is correct
111 Correct 69 ms 68936 KB Output is correct
112 Correct 70 ms 68892 KB Output is correct
113 Correct 69 ms 68960 KB Output is correct
114 Correct 68 ms 68932 KB Output is correct
115 Correct 111 ms 145320 KB Output is correct
116 Correct 106 ms 145296 KB Output is correct
117 Correct 115 ms 145348 KB Output is correct
118 Correct 107 ms 145340 KB Output is correct
119 Correct 106 ms 145284 KB Output is correct
120 Correct 80 ms 68900 KB Output is correct
121 Correct 66 ms 68904 KB Output is correct
122 Correct 67 ms 68960 KB Output is correct
123 Correct 68 ms 68928 KB Output is correct
124 Correct 77 ms 109988 KB Output is correct
125 Correct 79 ms 109980 KB Output is correct
126 Correct 78 ms 109976 KB Output is correct
127 Correct 77 ms 110020 KB Output is correct
128 Correct 31 ms 36300 KB Output is correct
129 Correct 29 ms 36308 KB Output is correct
130 Correct 29 ms 36304 KB Output is correct
131 Correct 0 ms 340 KB Output is correct