답안 #959738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959738 2024-04-09T02:27:54 Z LCJLY Homework (CEOI22_homework) C++14
100 / 100
177 ms 195232 KB
#include <bits/stdc++.h>
using namespace std;	
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
//typedef pair<pii,pii>pi2;
typedef array<int,3>pi2;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

string s;
int n;

vector<int>v[1000005];

int cnt=0;

pi2 dnc(int l, int r, int d){
	if(l==r){
		return {1,1,1};
	}
	else if(s[l+1]=='i'){
		int index=lower_bound(v[d].begin(),v[d].end(),l)-v[d].begin();
		index=v[d][index];
		pi2 a=dnc(l+4,index-1,d+1);
		pi2 b=dnc(index+1,r-1,d+1);
		
		return {min(a[0],b[0]),a[1]+b[1]-1,a[2]+b[2]};
	}
	else{
		int index=lower_bound(v[d].begin(),v[d].end(),l)-v[d].begin();
		index=v[d][index];
		pi2 a=dnc(l+4,index-1,d+1);
		pi2 b=dnc(index+1,r-1,d+1);
		
		return {a[0]+b[0],max(a[1]+b[2],b[1]+a[2]),a[2]+b[2]};
	}
}

void solve(){
	cin >> s;
	n=s.length();
	
	int lvl=0;
	for(int x=0;x<n;x++){
		if(s[x]=='('){
			lvl++;
		}
		else if(s[x]==')'){
			lvl--;
		}
		else if(s[x]==','){
			v[lvl].push_back(x);
		}
		//else if(s[x]=='?') cnt++;
	}
	
	pi2 hold=dnc(0,n-1,1);
	cout << hold[1]-hold[0]+1;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 23900 KB Output is correct
2 Correct 8 ms 23900 KB Output is correct
3 Correct 5 ms 23936 KB Output is correct
4 Correct 7 ms 23788 KB Output is correct
5 Correct 6 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 23948 KB Output is correct
10 Correct 7 ms 23948 KB Output is correct
11 Correct 6 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 6 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23912 KB Output is correct
20 Correct 5 ms 23900 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 7 ms 23900 KB Output is correct
23 Correct 5 ms 23944 KB Output is correct
24 Correct 6 ms 23900 KB Output is correct
25 Correct 6 ms 23896 KB Output is correct
26 Correct 6 ms 23900 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 6 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 23900 KB Output is correct
2 Correct 8 ms 23900 KB Output is correct
3 Correct 5 ms 23936 KB Output is correct
4 Correct 7 ms 23788 KB Output is correct
5 Correct 6 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 23948 KB Output is correct
10 Correct 7 ms 23948 KB Output is correct
11 Correct 6 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 6 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23912 KB Output is correct
20 Correct 5 ms 23900 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 7 ms 23900 KB Output is correct
23 Correct 5 ms 23944 KB Output is correct
24 Correct 6 ms 23900 KB Output is correct
25 Correct 6 ms 23896 KB Output is correct
26 Correct 6 ms 23900 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 6 ms 23900 KB Output is correct
29 Correct 6 ms 23900 KB Output is correct
30 Correct 6 ms 23952 KB Output is correct
31 Correct 6 ms 23900 KB Output is correct
32 Correct 6 ms 23900 KB Output is correct
33 Correct 6 ms 23932 KB Output is correct
34 Correct 7 ms 24408 KB Output is correct
35 Correct 7 ms 23916 KB Output is correct
36 Correct 5 ms 23900 KB Output is correct
37 Correct 5 ms 23904 KB Output is correct
38 Correct 5 ms 23896 KB Output is correct
39 Correct 6 ms 23896 KB Output is correct
40 Correct 6 ms 23904 KB Output is correct
41 Correct 5 ms 23908 KB Output is correct
42 Correct 6 ms 23900 KB Output is correct
43 Correct 5 ms 23896 KB Output is correct
44 Correct 6 ms 23900 KB Output is correct
45 Correct 6 ms 23896 KB Output is correct
46 Correct 6 ms 24152 KB Output is correct
47 Correct 7 ms 23900 KB Output is correct
48 Correct 6 ms 23900 KB Output is correct
49 Correct 6 ms 23768 KB Output is correct
50 Correct 6 ms 23900 KB Output is correct
51 Correct 5 ms 23900 KB Output is correct
52 Correct 6 ms 23900 KB Output is correct
53 Correct 6 ms 23900 KB Output is correct
54 Correct 6 ms 23948 KB Output is correct
55 Correct 6 ms 23900 KB Output is correct
56 Correct 6 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 187328 KB Output is correct
2 Correct 153 ms 187228 KB Output is correct
3 Correct 152 ms 187092 KB Output is correct
4 Correct 156 ms 188100 KB Output is correct
5 Correct 151 ms 195232 KB Output is correct
6 Correct 163 ms 194132 KB Output is correct
7 Correct 155 ms 194256 KB Output is correct
8 Correct 150 ms 195052 KB Output is correct
9 Correct 159 ms 194256 KB Output is correct
10 Correct 159 ms 194404 KB Output is correct
11 Correct 151 ms 194084 KB Output is correct
12 Correct 158 ms 194024 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 23900 KB Output is correct
2 Correct 8 ms 23900 KB Output is correct
3 Correct 5 ms 23936 KB Output is correct
4 Correct 7 ms 23788 KB Output is correct
5 Correct 6 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 23948 KB Output is correct
10 Correct 7 ms 23948 KB Output is correct
11 Correct 6 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 6 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23912 KB Output is correct
20 Correct 5 ms 23900 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 7 ms 23900 KB Output is correct
23 Correct 5 ms 23944 KB Output is correct
24 Correct 6 ms 23900 KB Output is correct
25 Correct 6 ms 23896 KB Output is correct
26 Correct 6 ms 23900 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 6 ms 23900 KB Output is correct
29 Correct 6 ms 23900 KB Output is correct
30 Correct 6 ms 23952 KB Output is correct
31 Correct 6 ms 23900 KB Output is correct
32 Correct 6 ms 23900 KB Output is correct
33 Correct 6 ms 23932 KB Output is correct
34 Correct 7 ms 24408 KB Output is correct
35 Correct 7 ms 23916 KB Output is correct
36 Correct 5 ms 23900 KB Output is correct
37 Correct 5 ms 23904 KB Output is correct
38 Correct 5 ms 23896 KB Output is correct
39 Correct 6 ms 23896 KB Output is correct
40 Correct 6 ms 23904 KB Output is correct
41 Correct 5 ms 23908 KB Output is correct
42 Correct 6 ms 23900 KB Output is correct
43 Correct 5 ms 23896 KB Output is correct
44 Correct 6 ms 23900 KB Output is correct
45 Correct 6 ms 23896 KB Output is correct
46 Correct 6 ms 24152 KB Output is correct
47 Correct 7 ms 23900 KB Output is correct
48 Correct 6 ms 23900 KB Output is correct
49 Correct 6 ms 23768 KB Output is correct
50 Correct 6 ms 23900 KB Output is correct
51 Correct 5 ms 23900 KB Output is correct
52 Correct 6 ms 23900 KB Output is correct
53 Correct 6 ms 23900 KB Output is correct
54 Correct 6 ms 23948 KB Output is correct
55 Correct 6 ms 23900 KB Output is correct
56 Correct 6 ms 23900 KB Output is correct
57 Correct 6 ms 23896 KB Output is correct
58 Correct 6 ms 23900 KB Output is correct
59 Correct 7 ms 23900 KB Output is correct
60 Correct 7 ms 23900 KB Output is correct
61 Correct 6 ms 23948 KB Output is correct
62 Correct 6 ms 23900 KB Output is correct
63 Correct 6 ms 23900 KB Output is correct
64 Correct 7 ms 23988 KB Output is correct
65 Correct 6 ms 23900 KB Output is correct
66 Correct 7 ms 23940 KB Output is correct
67 Correct 6 ms 23900 KB Output is correct
68 Correct 6 ms 23932 KB Output is correct
69 Correct 6 ms 24156 KB Output is correct
70 Correct 6 ms 23896 KB Output is correct
71 Correct 6 ms 23900 KB Output is correct
72 Correct 6 ms 23952 KB Output is correct
73 Correct 6 ms 23900 KB Output is correct
74 Correct 6 ms 24152 KB Output is correct
75 Correct 7 ms 23900 KB Output is correct
76 Correct 6 ms 23900 KB Output is correct
77 Correct 6 ms 23896 KB Output is correct
78 Correct 6 ms 23900 KB Output is correct
79 Correct 6 ms 23896 KB Output is correct
80 Correct 7 ms 23900 KB Output is correct
81 Correct 6 ms 23896 KB Output is correct
82 Correct 5 ms 23896 KB Output is correct
83 Correct 6 ms 23944 KB Output is correct
84 Correct 6 ms 23900 KB Output is correct
85 Correct 6 ms 23900 KB Output is correct
86 Correct 6 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 23900 KB Output is correct
2 Correct 8 ms 23900 KB Output is correct
3 Correct 5 ms 23936 KB Output is correct
4 Correct 7 ms 23788 KB Output is correct
5 Correct 6 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 23948 KB Output is correct
10 Correct 7 ms 23948 KB Output is correct
11 Correct 6 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 5 ms 23900 KB Output is correct
17 Correct 6 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23912 KB Output is correct
20 Correct 5 ms 23900 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 7 ms 23900 KB Output is correct
23 Correct 5 ms 23944 KB Output is correct
24 Correct 6 ms 23900 KB Output is correct
25 Correct 6 ms 23896 KB Output is correct
26 Correct 6 ms 23900 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 6 ms 23900 KB Output is correct
29 Correct 6 ms 23900 KB Output is correct
30 Correct 6 ms 23952 KB Output is correct
31 Correct 6 ms 23900 KB Output is correct
32 Correct 6 ms 23900 KB Output is correct
33 Correct 6 ms 23932 KB Output is correct
34 Correct 7 ms 24408 KB Output is correct
35 Correct 7 ms 23916 KB Output is correct
36 Correct 5 ms 23900 KB Output is correct
37 Correct 5 ms 23904 KB Output is correct
38 Correct 5 ms 23896 KB Output is correct
39 Correct 6 ms 23896 KB Output is correct
40 Correct 6 ms 23904 KB Output is correct
41 Correct 5 ms 23908 KB Output is correct
42 Correct 6 ms 23900 KB Output is correct
43 Correct 5 ms 23896 KB Output is correct
44 Correct 6 ms 23900 KB Output is correct
45 Correct 6 ms 23896 KB Output is correct
46 Correct 6 ms 24152 KB Output is correct
47 Correct 7 ms 23900 KB Output is correct
48 Correct 6 ms 23900 KB Output is correct
49 Correct 6 ms 23768 KB Output is correct
50 Correct 6 ms 23900 KB Output is correct
51 Correct 5 ms 23900 KB Output is correct
52 Correct 6 ms 23900 KB Output is correct
53 Correct 6 ms 23900 KB Output is correct
54 Correct 6 ms 23948 KB Output is correct
55 Correct 6 ms 23900 KB Output is correct
56 Correct 6 ms 23900 KB Output is correct
57 Correct 155 ms 187328 KB Output is correct
58 Correct 153 ms 187228 KB Output is correct
59 Correct 152 ms 187092 KB Output is correct
60 Correct 156 ms 188100 KB Output is correct
61 Correct 151 ms 195232 KB Output is correct
62 Correct 163 ms 194132 KB Output is correct
63 Correct 155 ms 194256 KB Output is correct
64 Correct 150 ms 195052 KB Output is correct
65 Correct 159 ms 194256 KB Output is correct
66 Correct 159 ms 194404 KB Output is correct
67 Correct 151 ms 194084 KB Output is correct
68 Correct 158 ms 194024 KB Output is correct
69 Correct 6 ms 23900 KB Output is correct
70 Correct 6 ms 23896 KB Output is correct
71 Correct 6 ms 23900 KB Output is correct
72 Correct 7 ms 23900 KB Output is correct
73 Correct 7 ms 23900 KB Output is correct
74 Correct 6 ms 23948 KB Output is correct
75 Correct 6 ms 23900 KB Output is correct
76 Correct 6 ms 23900 KB Output is correct
77 Correct 7 ms 23988 KB Output is correct
78 Correct 6 ms 23900 KB Output is correct
79 Correct 7 ms 23940 KB Output is correct
80 Correct 6 ms 23900 KB Output is correct
81 Correct 6 ms 23932 KB Output is correct
82 Correct 6 ms 24156 KB Output is correct
83 Correct 6 ms 23896 KB Output is correct
84 Correct 6 ms 23900 KB Output is correct
85 Correct 6 ms 23952 KB Output is correct
86 Correct 6 ms 23900 KB Output is correct
87 Correct 6 ms 24152 KB Output is correct
88 Correct 7 ms 23900 KB Output is correct
89 Correct 6 ms 23900 KB Output is correct
90 Correct 6 ms 23896 KB Output is correct
91 Correct 6 ms 23900 KB Output is correct
92 Correct 6 ms 23896 KB Output is correct
93 Correct 7 ms 23900 KB Output is correct
94 Correct 6 ms 23896 KB Output is correct
95 Correct 5 ms 23896 KB Output is correct
96 Correct 6 ms 23944 KB Output is correct
97 Correct 6 ms 23900 KB Output is correct
98 Correct 6 ms 23900 KB Output is correct
99 Correct 6 ms 23936 KB Output is correct
100 Correct 111 ms 50152 KB Output is correct
101 Correct 107 ms 49708 KB Output is correct
102 Correct 99 ms 51160 KB Output is correct
103 Correct 102 ms 51440 KB Output is correct
104 Correct 105 ms 49620 KB Output is correct
105 Correct 124 ms 95488 KB Output is correct
106 Correct 123 ms 95492 KB Output is correct
107 Correct 118 ms 95324 KB Output is correct
108 Correct 115 ms 96456 KB Output is correct
109 Correct 113 ms 95320 KB Output is correct
110 Correct 124 ms 49416 KB Output is correct
111 Correct 120 ms 49440 KB Output is correct
112 Correct 120 ms 49364 KB Output is correct
113 Correct 131 ms 49448 KB Output is correct
114 Correct 116 ms 48760 KB Output is correct
115 Correct 177 ms 193972 KB Output is correct
116 Correct 164 ms 195116 KB Output is correct
117 Correct 148 ms 194000 KB Output is correct
118 Correct 153 ms 195096 KB Output is correct
119 Correct 145 ms 194624 KB Output is correct
120 Correct 116 ms 49668 KB Output is correct
121 Correct 109 ms 49224 KB Output is correct
122 Correct 115 ms 49392 KB Output is correct
123 Correct 123 ms 49852 KB Output is correct
124 Correct 132 ms 122396 KB Output is correct
125 Correct 118 ms 122604 KB Output is correct
126 Correct 113 ms 121840 KB Output is correct
127 Correct 117 ms 122344 KB Output is correct
128 Correct 45 ms 35040 KB Output is correct
129 Correct 48 ms 35044 KB Output is correct
130 Correct 42 ms 35164 KB Output is correct
131 Correct 5 ms 23900 KB Output is correct