답안 #972405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972405 2024-04-30T11:44:37 Z 8pete8 Homework (CEOI22_homework) C++17
100 / 100
133 ms 187840 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib> 
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
//#define int long long
#define double long double
const int mod=998244353,mxn=1e7+5,lg=60,inf=1e9,minf=-1e9,Mxn=1e6+50000;
int sz[mxn+10];
int st[mxn+10],ed[mxn+10],type[mxn+10];
pii child[mxn+10];
string a;
pii solve(int id){
	if(a[id]=='?'){
		sz[id]=1;
		return {1,1};
	}
	pii vl,vr;
	vl=solve(child[id].f),vr=solve(child[id].s);
	sz[id]=sz[child[id].s]+sz[child[id].f];
	if(type[id])return {min(vl.f,vr.f),vr.s+vl.s-1};
	else return {vl.f+vr.f,max(vl.s+sz[child[id].s],vr.s+sz[child[id].f])};
}
int32_t main(){
	fastio
	cin>>a;
	if(a=="?")return cout<<1,0;
	stack<int>st;
	for(int i=0;i<a.size();i++)child[i]={-1,-1};
	for(int i=0;i<a.size();i++){
		sz[i]=0;
		if(a[i]=='('){
			type[i]=(a[i-1]=='n');
			st.push(i);
		}
		else if(a[i]==')'){
			int x=st.top();
			ed[x]=i;
			st.pop();
			if(st.empty())continue;
			if(child[st.top()].f==-1)child[st.top()].f=x;
			else child[st.top()].s=x;
		}
		else if(a[i]=='?'){
			if(child[st.top()].f==-1)child[st.top()].f=i;
			else child[st.top()].s=i;
		}
	}
	pii ans=solve(3);
	cout<<ans.s-ans.f+1;
	return 0;
}
/*
keep range l,r->value thats obtainable in subtree
l being the min number of number < x needed to be used
and r being the max
merging-{
	min node{
		nl=min(l1,l2)-> push value of every node of the other subtree up
		nr=(r1+r2-1)->push 1 at the bottom of the other except 1
	}
	max node{
		nl=l1+l2->push 1 at bottom
		nr=r1+subsz2 or r2+subsz1 ->taking everything and shift it
	}
}

*/

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i=0;i<a.size();i++)child[i]={-1,-1};
      |              ~^~~~~~~~~
Main.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6604 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6604 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6764 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6752 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6620 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6604 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6604 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6764 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6752 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6620 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6608 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6608 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6488 KB Output is correct
53 Correct 1 ms 6488 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6644 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 186412 KB Output is correct
2 Correct 124 ms 186824 KB Output is correct
3 Correct 124 ms 187192 KB Output is correct
4 Correct 130 ms 187600 KB Output is correct
5 Correct 121 ms 186632 KB Output is correct
6 Correct 121 ms 186320 KB Output is correct
7 Correct 118 ms 187340 KB Output is correct
8 Correct 124 ms 186500 KB Output is correct
9 Correct 133 ms 186536 KB Output is correct
10 Correct 126 ms 186340 KB Output is correct
11 Correct 129 ms 186944 KB Output is correct
12 Correct 120 ms 186424 KB Output is correct
13 Correct 1 ms 6496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6604 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6604 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6764 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6752 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6620 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6608 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6608 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6488 KB Output is correct
53 Correct 1 ms 6488 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6644 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 2 ms 6492 KB Output is correct
58 Correct 1 ms 6492 KB Output is correct
59 Correct 1 ms 6492 KB Output is correct
60 Correct 1 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 1 ms 6604 KB Output is correct
63 Correct 1 ms 6492 KB Output is correct
64 Correct 1 ms 6488 KB Output is correct
65 Correct 1 ms 6492 KB Output is correct
66 Correct 1 ms 6612 KB Output is correct
67 Correct 1 ms 6492 KB Output is correct
68 Correct 1 ms 6492 KB Output is correct
69 Correct 1 ms 6492 KB Output is correct
70 Correct 1 ms 6492 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 1 ms 6488 KB Output is correct
73 Correct 1 ms 6608 KB Output is correct
74 Correct 1 ms 6492 KB Output is correct
75 Correct 1 ms 6492 KB Output is correct
76 Correct 1 ms 6492 KB Output is correct
77 Correct 1 ms 6744 KB Output is correct
78 Correct 1 ms 6488 KB Output is correct
79 Correct 1 ms 6488 KB Output is correct
80 Correct 1 ms 6492 KB Output is correct
81 Correct 1 ms 6492 KB Output is correct
82 Correct 1 ms 6492 KB Output is correct
83 Correct 1 ms 6488 KB Output is correct
84 Correct 1 ms 6492 KB Output is correct
85 Correct 1 ms 6492 KB Output is correct
86 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6604 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6604 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6488 KB Output is correct
21 Correct 1 ms 6764 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6752 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6620 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6608 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6608 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6492 KB Output is correct
52 Correct 1 ms 6488 KB Output is correct
53 Correct 1 ms 6488 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6644 KB Output is correct
56 Correct 1 ms 6492 KB Output is correct
57 Correct 121 ms 186412 KB Output is correct
58 Correct 124 ms 186824 KB Output is correct
59 Correct 124 ms 187192 KB Output is correct
60 Correct 130 ms 187600 KB Output is correct
61 Correct 121 ms 186632 KB Output is correct
62 Correct 121 ms 186320 KB Output is correct
63 Correct 118 ms 187340 KB Output is correct
64 Correct 124 ms 186500 KB Output is correct
65 Correct 133 ms 186536 KB Output is correct
66 Correct 126 ms 186340 KB Output is correct
67 Correct 129 ms 186944 KB Output is correct
68 Correct 120 ms 186424 KB Output is correct
69 Correct 1 ms 6496 KB Output is correct
70 Correct 2 ms 6492 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 1 ms 6492 KB Output is correct
73 Correct 1 ms 6492 KB Output is correct
74 Correct 2 ms 6492 KB Output is correct
75 Correct 1 ms 6604 KB Output is correct
76 Correct 1 ms 6492 KB Output is correct
77 Correct 1 ms 6488 KB Output is correct
78 Correct 1 ms 6492 KB Output is correct
79 Correct 1 ms 6612 KB Output is correct
80 Correct 1 ms 6492 KB Output is correct
81 Correct 1 ms 6492 KB Output is correct
82 Correct 1 ms 6492 KB Output is correct
83 Correct 1 ms 6492 KB Output is correct
84 Correct 1 ms 6492 KB Output is correct
85 Correct 1 ms 6488 KB Output is correct
86 Correct 1 ms 6608 KB Output is correct
87 Correct 1 ms 6492 KB Output is correct
88 Correct 1 ms 6492 KB Output is correct
89 Correct 1 ms 6492 KB Output is correct
90 Correct 1 ms 6744 KB Output is correct
91 Correct 1 ms 6488 KB Output is correct
92 Correct 1 ms 6488 KB Output is correct
93 Correct 1 ms 6492 KB Output is correct
94 Correct 1 ms 6492 KB Output is correct
95 Correct 1 ms 6492 KB Output is correct
96 Correct 1 ms 6488 KB Output is correct
97 Correct 1 ms 6492 KB Output is correct
98 Correct 1 ms 6492 KB Output is correct
99 Correct 1 ms 6492 KB Output is correct
100 Correct 90 ms 152400 KB Output is correct
101 Correct 90 ms 151248 KB Output is correct
102 Correct 86 ms 152016 KB Output is correct
103 Correct 89 ms 152352 KB Output is correct
104 Correct 85 ms 151504 KB Output is correct
105 Correct 104 ms 168656 KB Output is correct
106 Correct 106 ms 168036 KB Output is correct
107 Correct 101 ms 168784 KB Output is correct
108 Correct 101 ms 167996 KB Output is correct
109 Correct 99 ms 168144 KB Output is correct
110 Correct 99 ms 152516 KB Output is correct
111 Correct 98 ms 151760 KB Output is correct
112 Correct 93 ms 152140 KB Output is correct
113 Correct 90 ms 151048 KB Output is correct
114 Correct 95 ms 152596 KB Output is correct
115 Correct 121 ms 186320 KB Output is correct
116 Correct 121 ms 187328 KB Output is correct
117 Correct 118 ms 186424 KB Output is correct
118 Correct 123 ms 187840 KB Output is correct
119 Correct 115 ms 186832 KB Output is correct
120 Correct 94 ms 151108 KB Output is correct
121 Correct 94 ms 152276 KB Output is correct
122 Correct 99 ms 152452 KB Output is correct
123 Correct 96 ms 151868 KB Output is correct
124 Correct 97 ms 173008 KB Output is correct
125 Correct 97 ms 172636 KB Output is correct
126 Correct 99 ms 173184 KB Output is correct
127 Correct 100 ms 172516 KB Output is correct
128 Correct 41 ms 79424 KB Output is correct
129 Correct 40 ms 79824 KB Output is correct
130 Correct 40 ms 79572 KB Output is correct
131 Correct 1 ms 6488 KB Output is correct