답안 #814136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
814136 2023-08-08T05:46:50 Z 이동현(#10122) Security Gate (JOI18_security_gate) C++17
30 / 100
1624 ms 340 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	if(n % 2){
		cout << "0\n";

		return 0;
	}
	string s;
	cin >> s;

	vector<int> x;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'x'){
			x.push_back(i);
		}
	}

	int ans = 0;
	for(int bt = 0; bt < 1 << (int)x.size(); ++bt){
		for(int i = 0; i < (int)x.size(); ++i){
			s[x[i]] = ((bt & (1 << i)) ? '(' : ')');
		}

		vector<int> pre(n);
		for(int i = 0; i < n; ++i){
			pre[i] = s[i] == '(' ? 1 : -1;
			if(i) pre[i] += pre[i - 1];
		}

		int can = 0;
		for(int i = 0, si = 0; i <= n && si >= 0; ++i){
			for(int j = n, sj = 0; j >= i && sj >= 0; --j){
				if(j) sj += s[j - 1] == ')' ? 1 : -1;

				if((i ? pre[i - 1] : 0) + pre[n - 1] / 2 == (j ? pre[j - 1] : 0)){
					int mx = 0;

					for(int k = i; k < j; ++k){
						mx = max(mx, pre[k]);
					}

					if((i ? pre[i - 1] : 0) * 2 >= mx){
						can = 1;

						break;
					}
				}
			}
			if(can) break;

			if(i < n) si += s[i] == '(' ? 1 : -1;
		}

		ans += can;
	}

	cout << ans << '\n';
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 12 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 12 ms 316 KB Output is correct
32 Correct 8 ms 316 KB Output is correct
33 Correct 3 ms 212 KB Output is correct
34 Correct 248 ms 300 KB Output is correct
35 Correct 7 ms 212 KB Output is correct
36 Correct 29 ms 300 KB Output is correct
37 Correct 327 ms 304 KB Output is correct
38 Correct 775 ms 296 KB Output is correct
39 Correct 7 ms 316 KB Output is correct
40 Correct 982 ms 296 KB Output is correct
41 Correct 803 ms 340 KB Output is correct
42 Correct 1160 ms 304 KB Output is correct
43 Correct 1240 ms 296 KB Output is correct
44 Correct 85 ms 300 KB Output is correct
45 Correct 1624 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 12 ms 316 KB Output is correct
32 Correct 8 ms 316 KB Output is correct
33 Correct 3 ms 212 KB Output is correct
34 Correct 248 ms 300 KB Output is correct
35 Correct 7 ms 212 KB Output is correct
36 Correct 29 ms 300 KB Output is correct
37 Correct 327 ms 304 KB Output is correct
38 Correct 775 ms 296 KB Output is correct
39 Correct 7 ms 316 KB Output is correct
40 Correct 982 ms 296 KB Output is correct
41 Correct 803 ms 340 KB Output is correct
42 Correct 1160 ms 304 KB Output is correct
43 Correct 1240 ms 296 KB Output is correct
44 Correct 85 ms 300 KB Output is correct
45 Correct 1624 ms 304 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 316 KB Output is correct
49 Incorrect 1 ms 212 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 12 ms 316 KB Output is correct
32 Correct 8 ms 316 KB Output is correct
33 Correct 3 ms 212 KB Output is correct
34 Correct 248 ms 300 KB Output is correct
35 Correct 7 ms 212 KB Output is correct
36 Correct 29 ms 300 KB Output is correct
37 Correct 327 ms 304 KB Output is correct
38 Correct 775 ms 296 KB Output is correct
39 Correct 7 ms 316 KB Output is correct
40 Correct 982 ms 296 KB Output is correct
41 Correct 803 ms 340 KB Output is correct
42 Correct 1160 ms 304 KB Output is correct
43 Correct 1240 ms 296 KB Output is correct
44 Correct 85 ms 300 KB Output is correct
45 Correct 1624 ms 304 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 316 KB Output is correct
49 Incorrect 1 ms 212 KB Output isn't correct
50 Halted 0 ms 0 KB -