답안 #725903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725903 2023-04-18T08:38:14 Z Baytoro Homework (CEOI22_homework) C++17
100 / 100
206 ms 159208 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e6+5;
vector<int> g[N];
int t[N],m;
pair<int,int> dfs(int x){
	if(!g[x].size()) return {1,m};
	pair<int,int> a=dfs(g[x][0]);
	pair<int,int> b=dfs(g[x][1]);
	if(t[x]==1){
		int l=min(a.fr,b.fr);
		int r=a.sc+b.sc-(m+1);
		return {l,r};
	}
	else{
		int l=a.fr+b.fr;
		int r=max(a.sc,b.sc);
		return {l,r};
	}
}
void solve(){
	string s;cin>>s;int n=s.size();m=0;
	stack<int> st;
	int cur=0;
	for(int i=0;i<n;i++){
		if(s[i]=='n'){
			cur++;
			if(!st.empty()){
				g[st.top()].pb(cur);
			}
			t[cur]=1;
			st.push(cur);
		}
		if(s[i]=='x'){
			cur++;
			if(!st.empty()){
				g[st.top()].pb(cur);
			}
			t[cur]=2;
			st.push(cur);
		}
		if(s[i]=='?'){
			cur++;m++;
			g[st.top()].pb(cur);
		}
		if(s[i]==')') st.pop();
	}
	pair<int,int> ans=dfs(1);
	cout<<ans.sc-ans.fr+1<<endl;
}
main(){
	//fopn("team");
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

Main.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   64 | main(){
      | ^~~~
Main.cpp: In function 'void fopn(std::string)':
Main.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47224 KB Output is correct
2 Correct 24 ms 47392 KB Output is correct
3 Correct 26 ms 47280 KB Output is correct
4 Correct 28 ms 47296 KB Output is correct
5 Correct 27 ms 47188 KB Output is correct
6 Correct 25 ms 47188 KB Output is correct
7 Correct 25 ms 47248 KB Output is correct
8 Correct 25 ms 47180 KB Output is correct
9 Correct 24 ms 47292 KB Output is correct
10 Correct 25 ms 47292 KB Output is correct
11 Correct 25 ms 47188 KB Output is correct
12 Correct 25 ms 47240 KB Output is correct
13 Correct 24 ms 47188 KB Output is correct
14 Correct 25 ms 47204 KB Output is correct
15 Correct 24 ms 47276 KB Output is correct
16 Correct 25 ms 47296 KB Output is correct
17 Correct 25 ms 47188 KB Output is correct
18 Correct 25 ms 47212 KB Output is correct
19 Correct 25 ms 47216 KB Output is correct
20 Correct 25 ms 47188 KB Output is correct
21 Correct 25 ms 47264 KB Output is correct
22 Correct 25 ms 47216 KB Output is correct
23 Correct 25 ms 47184 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 25 ms 47168 KB Output is correct
27 Correct 25 ms 47188 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47224 KB Output is correct
2 Correct 24 ms 47392 KB Output is correct
3 Correct 26 ms 47280 KB Output is correct
4 Correct 28 ms 47296 KB Output is correct
5 Correct 27 ms 47188 KB Output is correct
6 Correct 25 ms 47188 KB Output is correct
7 Correct 25 ms 47248 KB Output is correct
8 Correct 25 ms 47180 KB Output is correct
9 Correct 24 ms 47292 KB Output is correct
10 Correct 25 ms 47292 KB Output is correct
11 Correct 25 ms 47188 KB Output is correct
12 Correct 25 ms 47240 KB Output is correct
13 Correct 24 ms 47188 KB Output is correct
14 Correct 25 ms 47204 KB Output is correct
15 Correct 24 ms 47276 KB Output is correct
16 Correct 25 ms 47296 KB Output is correct
17 Correct 25 ms 47188 KB Output is correct
18 Correct 25 ms 47212 KB Output is correct
19 Correct 25 ms 47216 KB Output is correct
20 Correct 25 ms 47188 KB Output is correct
21 Correct 25 ms 47264 KB Output is correct
22 Correct 25 ms 47216 KB Output is correct
23 Correct 25 ms 47184 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 25 ms 47168 KB Output is correct
27 Correct 25 ms 47188 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 25 ms 47292 KB Output is correct
30 Correct 25 ms 47224 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 25 ms 47188 KB Output is correct
33 Correct 25 ms 47176 KB Output is correct
34 Correct 25 ms 47276 KB Output is correct
35 Correct 26 ms 47296 KB Output is correct
36 Correct 25 ms 47228 KB Output is correct
37 Correct 25 ms 47368 KB Output is correct
38 Correct 26 ms 47300 KB Output is correct
39 Correct 25 ms 47284 KB Output is correct
40 Correct 27 ms 47296 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 25 ms 47188 KB Output is correct
44 Correct 24 ms 47228 KB Output is correct
45 Correct 25 ms 47196 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 29 ms 47184 KB Output is correct
48 Correct 25 ms 47188 KB Output is correct
49 Correct 28 ms 47280 KB Output is correct
50 Correct 24 ms 47188 KB Output is correct
51 Correct 25 ms 47300 KB Output is correct
52 Correct 25 ms 47260 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47180 KB Output is correct
55 Correct 25 ms 47188 KB Output is correct
56 Correct 25 ms 47204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 157532 KB Output is correct
2 Correct 193 ms 156524 KB Output is correct
3 Correct 204 ms 156592 KB Output is correct
4 Correct 204 ms 156548 KB Output is correct
5 Correct 195 ms 156584 KB Output is correct
6 Correct 196 ms 156648 KB Output is correct
7 Correct 194 ms 156616 KB Output is correct
8 Correct 199 ms 156704 KB Output is correct
9 Correct 194 ms 156740 KB Output is correct
10 Correct 192 ms 156744 KB Output is correct
11 Correct 189 ms 156708 KB Output is correct
12 Correct 187 ms 156976 KB Output is correct
13 Correct 27 ms 47188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47224 KB Output is correct
2 Correct 24 ms 47392 KB Output is correct
3 Correct 26 ms 47280 KB Output is correct
4 Correct 28 ms 47296 KB Output is correct
5 Correct 27 ms 47188 KB Output is correct
6 Correct 25 ms 47188 KB Output is correct
7 Correct 25 ms 47248 KB Output is correct
8 Correct 25 ms 47180 KB Output is correct
9 Correct 24 ms 47292 KB Output is correct
10 Correct 25 ms 47292 KB Output is correct
11 Correct 25 ms 47188 KB Output is correct
12 Correct 25 ms 47240 KB Output is correct
13 Correct 24 ms 47188 KB Output is correct
14 Correct 25 ms 47204 KB Output is correct
15 Correct 24 ms 47276 KB Output is correct
16 Correct 25 ms 47296 KB Output is correct
17 Correct 25 ms 47188 KB Output is correct
18 Correct 25 ms 47212 KB Output is correct
19 Correct 25 ms 47216 KB Output is correct
20 Correct 25 ms 47188 KB Output is correct
21 Correct 25 ms 47264 KB Output is correct
22 Correct 25 ms 47216 KB Output is correct
23 Correct 25 ms 47184 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 25 ms 47168 KB Output is correct
27 Correct 25 ms 47188 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 25 ms 47292 KB Output is correct
30 Correct 25 ms 47224 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 25 ms 47188 KB Output is correct
33 Correct 25 ms 47176 KB Output is correct
34 Correct 25 ms 47276 KB Output is correct
35 Correct 26 ms 47296 KB Output is correct
36 Correct 25 ms 47228 KB Output is correct
37 Correct 25 ms 47368 KB Output is correct
38 Correct 26 ms 47300 KB Output is correct
39 Correct 25 ms 47284 KB Output is correct
40 Correct 27 ms 47296 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 25 ms 47188 KB Output is correct
44 Correct 24 ms 47228 KB Output is correct
45 Correct 25 ms 47196 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 29 ms 47184 KB Output is correct
48 Correct 25 ms 47188 KB Output is correct
49 Correct 28 ms 47280 KB Output is correct
50 Correct 24 ms 47188 KB Output is correct
51 Correct 25 ms 47300 KB Output is correct
52 Correct 25 ms 47260 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47180 KB Output is correct
55 Correct 25 ms 47188 KB Output is correct
56 Correct 25 ms 47204 KB Output is correct
57 Correct 25 ms 47400 KB Output is correct
58 Correct 25 ms 47292 KB Output is correct
59 Correct 25 ms 47324 KB Output is correct
60 Correct 27 ms 47300 KB Output is correct
61 Correct 25 ms 47308 KB Output is correct
62 Correct 26 ms 47300 KB Output is correct
63 Correct 25 ms 47360 KB Output is correct
64 Correct 25 ms 47316 KB Output is correct
65 Correct 25 ms 47316 KB Output is correct
66 Correct 26 ms 47336 KB Output is correct
67 Correct 25 ms 47316 KB Output is correct
68 Correct 24 ms 47280 KB Output is correct
69 Correct 25 ms 47300 KB Output is correct
70 Correct 24 ms 47316 KB Output is correct
71 Correct 25 ms 47248 KB Output is correct
72 Correct 25 ms 47404 KB Output is correct
73 Correct 25 ms 47404 KB Output is correct
74 Correct 24 ms 47308 KB Output is correct
75 Correct 25 ms 47316 KB Output is correct
76 Correct 24 ms 47316 KB Output is correct
77 Correct 25 ms 47296 KB Output is correct
78 Correct 25 ms 47280 KB Output is correct
79 Correct 25 ms 47240 KB Output is correct
80 Correct 25 ms 47364 KB Output is correct
81 Correct 26 ms 47364 KB Output is correct
82 Correct 26 ms 47328 KB Output is correct
83 Correct 25 ms 47316 KB Output is correct
84 Correct 24 ms 47252 KB Output is correct
85 Correct 24 ms 47296 KB Output is correct
86 Correct 25 ms 47208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47224 KB Output is correct
2 Correct 24 ms 47392 KB Output is correct
3 Correct 26 ms 47280 KB Output is correct
4 Correct 28 ms 47296 KB Output is correct
5 Correct 27 ms 47188 KB Output is correct
6 Correct 25 ms 47188 KB Output is correct
7 Correct 25 ms 47248 KB Output is correct
8 Correct 25 ms 47180 KB Output is correct
9 Correct 24 ms 47292 KB Output is correct
10 Correct 25 ms 47292 KB Output is correct
11 Correct 25 ms 47188 KB Output is correct
12 Correct 25 ms 47240 KB Output is correct
13 Correct 24 ms 47188 KB Output is correct
14 Correct 25 ms 47204 KB Output is correct
15 Correct 24 ms 47276 KB Output is correct
16 Correct 25 ms 47296 KB Output is correct
17 Correct 25 ms 47188 KB Output is correct
18 Correct 25 ms 47212 KB Output is correct
19 Correct 25 ms 47216 KB Output is correct
20 Correct 25 ms 47188 KB Output is correct
21 Correct 25 ms 47264 KB Output is correct
22 Correct 25 ms 47216 KB Output is correct
23 Correct 25 ms 47184 KB Output is correct
24 Correct 23 ms 47188 KB Output is correct
25 Correct 24 ms 47188 KB Output is correct
26 Correct 25 ms 47168 KB Output is correct
27 Correct 25 ms 47188 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 25 ms 47292 KB Output is correct
30 Correct 25 ms 47224 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 25 ms 47188 KB Output is correct
33 Correct 25 ms 47176 KB Output is correct
34 Correct 25 ms 47276 KB Output is correct
35 Correct 26 ms 47296 KB Output is correct
36 Correct 25 ms 47228 KB Output is correct
37 Correct 25 ms 47368 KB Output is correct
38 Correct 26 ms 47300 KB Output is correct
39 Correct 25 ms 47284 KB Output is correct
40 Correct 27 ms 47296 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 25 ms 47188 KB Output is correct
44 Correct 24 ms 47228 KB Output is correct
45 Correct 25 ms 47196 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 29 ms 47184 KB Output is correct
48 Correct 25 ms 47188 KB Output is correct
49 Correct 28 ms 47280 KB Output is correct
50 Correct 24 ms 47188 KB Output is correct
51 Correct 25 ms 47300 KB Output is correct
52 Correct 25 ms 47260 KB Output is correct
53 Correct 25 ms 47188 KB Output is correct
54 Correct 25 ms 47180 KB Output is correct
55 Correct 25 ms 47188 KB Output is correct
56 Correct 25 ms 47204 KB Output is correct
57 Correct 199 ms 157532 KB Output is correct
58 Correct 193 ms 156524 KB Output is correct
59 Correct 204 ms 156592 KB Output is correct
60 Correct 204 ms 156548 KB Output is correct
61 Correct 195 ms 156584 KB Output is correct
62 Correct 196 ms 156648 KB Output is correct
63 Correct 194 ms 156616 KB Output is correct
64 Correct 199 ms 156704 KB Output is correct
65 Correct 194 ms 156740 KB Output is correct
66 Correct 192 ms 156744 KB Output is correct
67 Correct 189 ms 156708 KB Output is correct
68 Correct 187 ms 156976 KB Output is correct
69 Correct 27 ms 47188 KB Output is correct
70 Correct 25 ms 47400 KB Output is correct
71 Correct 25 ms 47292 KB Output is correct
72 Correct 25 ms 47324 KB Output is correct
73 Correct 27 ms 47300 KB Output is correct
74 Correct 25 ms 47308 KB Output is correct
75 Correct 26 ms 47300 KB Output is correct
76 Correct 25 ms 47360 KB Output is correct
77 Correct 25 ms 47316 KB Output is correct
78 Correct 25 ms 47316 KB Output is correct
79 Correct 26 ms 47336 KB Output is correct
80 Correct 25 ms 47316 KB Output is correct
81 Correct 24 ms 47280 KB Output is correct
82 Correct 25 ms 47300 KB Output is correct
83 Correct 24 ms 47316 KB Output is correct
84 Correct 25 ms 47248 KB Output is correct
85 Correct 25 ms 47404 KB Output is correct
86 Correct 25 ms 47404 KB Output is correct
87 Correct 24 ms 47308 KB Output is correct
88 Correct 25 ms 47316 KB Output is correct
89 Correct 24 ms 47316 KB Output is correct
90 Correct 25 ms 47296 KB Output is correct
91 Correct 25 ms 47280 KB Output is correct
92 Correct 25 ms 47240 KB Output is correct
93 Correct 25 ms 47364 KB Output is correct
94 Correct 26 ms 47364 KB Output is correct
95 Correct 26 ms 47328 KB Output is correct
96 Correct 25 ms 47316 KB Output is correct
97 Correct 24 ms 47252 KB Output is correct
98 Correct 24 ms 47296 KB Output is correct
99 Correct 25 ms 47208 KB Output is correct
100 Correct 172 ms 107912 KB Output is correct
101 Correct 175 ms 107932 KB Output is correct
102 Correct 162 ms 107920 KB Output is correct
103 Correct 181 ms 107900 KB Output is correct
104 Correct 167 ms 107900 KB Output is correct
105 Correct 193 ms 123804 KB Output is correct
106 Correct 197 ms 123708 KB Output is correct
107 Correct 188 ms 123640 KB Output is correct
108 Correct 186 ms 123664 KB Output is correct
109 Correct 190 ms 123724 KB Output is correct
110 Correct 171 ms 107812 KB Output is correct
111 Correct 176 ms 107908 KB Output is correct
112 Correct 173 ms 107972 KB Output is correct
113 Correct 175 ms 107956 KB Output is correct
114 Correct 169 ms 107908 KB Output is correct
115 Correct 206 ms 159208 KB Output is correct
116 Correct 204 ms 159060 KB Output is correct
117 Correct 198 ms 159164 KB Output is correct
118 Correct 199 ms 159140 KB Output is correct
119 Correct 193 ms 159152 KB Output is correct
120 Correct 166 ms 107820 KB Output is correct
121 Correct 176 ms 107860 KB Output is correct
122 Correct 174 ms 107844 KB Output is correct
123 Correct 172 ms 107936 KB Output is correct
124 Correct 168 ms 135556 KB Output is correct
125 Correct 171 ms 135480 KB Output is correct
126 Correct 170 ms 135460 KB Output is correct
127 Correct 168 ms 135488 KB Output is correct
128 Correct 100 ms 79056 KB Output is correct
129 Correct 94 ms 78992 KB Output is correct
130 Correct 90 ms 78968 KB Output is correct
131 Correct 25 ms 47188 KB Output is correct