답안 #837675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837675 2023-08-25T14:01:36 Z MohamedAhmed04 Homework (CEOI22_homework) C++14
53 / 100
98 ms 121320 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e6 + 10 ;

string s ;

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

vector< vector<int> >adj(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:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0 ; i < s.size() ; ++i)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23952 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23772 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23800 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23952 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23772 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23800 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23832 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23764 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 12 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 11 ms 23764 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 12 ms 23764 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23764 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 14 ms 23800 KB Output is correct
56 Correct 12 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 121320 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23952 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23772 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23800 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23832 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23764 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 12 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 11 ms 23764 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 12 ms 23764 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23764 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 14 ms 23800 KB Output is correct
56 Correct 12 ms 23764 KB Output is correct
57 Correct 13 ms 23892 KB Output is correct
58 Correct 12 ms 23892 KB Output is correct
59 Correct 15 ms 23892 KB Output is correct
60 Correct 12 ms 23892 KB Output is correct
61 Correct 11 ms 23892 KB Output is correct
62 Correct 11 ms 23892 KB Output is correct
63 Correct 12 ms 23968 KB Output is correct
64 Correct 11 ms 23892 KB Output is correct
65 Correct 11 ms 23892 KB Output is correct
66 Correct 11 ms 23892 KB Output is correct
67 Correct 11 ms 23892 KB Output is correct
68 Correct 14 ms 23892 KB Output is correct
69 Correct 12 ms 23892 KB Output is correct
70 Correct 12 ms 23840 KB Output is correct
71 Correct 14 ms 23888 KB Output is correct
72 Correct 15 ms 24000 KB Output is correct
73 Correct 12 ms 24020 KB Output is correct
74 Correct 11 ms 23892 KB Output is correct
75 Correct 12 ms 23892 KB Output is correct
76 Correct 11 ms 23892 KB Output is correct
77 Correct 13 ms 23892 KB Output is correct
78 Correct 12 ms 23892 KB Output is correct
79 Correct 14 ms 23892 KB Output is correct
80 Correct 12 ms 23892 KB Output is correct
81 Correct 12 ms 23892 KB Output is correct
82 Correct 12 ms 23892 KB Output is correct
83 Correct 12 ms 23828 KB Output is correct
84 Correct 12 ms 23892 KB Output is correct
85 Correct 12 ms 23892 KB Output is correct
86 Correct 12 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23952 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23772 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 11 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23764 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 12 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23800 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23764 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 13 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23832 KB Output is correct
31 Correct 12 ms 23764 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 12 ms 23764 KB Output is correct
39 Correct 12 ms 23764 KB Output is correct
40 Correct 12 ms 23764 KB Output is correct
41 Correct 12 ms 23764 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 11 ms 23764 KB Output is correct
45 Correct 12 ms 23764 KB Output is correct
46 Correct 12 ms 23764 KB Output is correct
47 Correct 12 ms 23764 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23764 KB Output is correct
50 Correct 11 ms 23764 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 12 ms 23764 KB Output is correct
53 Correct 12 ms 23764 KB Output is correct
54 Correct 14 ms 23764 KB Output is correct
55 Correct 14 ms 23800 KB Output is correct
56 Correct 12 ms 23764 KB Output is correct
57 Runtime error 98 ms 121320 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -