Submission #680099

# Submission time Handle Problem Language Result Execution time Memory
680099 2023-01-09T22:44:55 Z rainboy Security Gate (JOI18_security_gate) C
30 / 100
333 ms 340 KB
#include <stdio.h>

#define N	300
#define K	20

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int solve(char *cc, int n) {
	static int xx[N + 1];
	int i, a, b, l, r;

	xx[0] = 0;
	for (i = 0; i < n; i++)
		xx[i + 1] = xx[i] + (cc[i] == '(' ? 1 : -1);
	if (xx[n] % 2 != 0)
		return 0;
	for (l = 0; l <= n; l++)
		if (xx[l] < 0)
			break;
	l--;
	for (r = n; r >= 0; r--)
		if (xx[r] - xx[n] < 0)
			break;
	r++;
	a = xx[0];
	for (i = 0; i <= l; i++)
		a = max(a, xx[i]);
	b = xx[n];
	for (i = r; i <= n; i++)
		b = max(b, xx[i]);
	if (l == n && r == 0)
		return 1;
	else if (l == n) {
		for (i = n; i >= 0; i--) {
			if ((b - xx[n] / 2) * 2 - xx[i] < 0)
				return 0;
			if (b - xx[i] == xx[n] / 2)
				return 1;
		}
		return 0;
	} else if (r == 0) {
		for (i = 0; i <= n; i++) {
			if (a * 2 - xx[i] < 0)
				return 0;
			if (xx[i] - a == xx[n] / 2)
				return 1;
		}
		return 0;
	} else {
		for (i = l; i <= r; i++)
			if (min(a, b - xx[n] / 2) * 2 - xx[i] < 0)
				return 0;
		return 1;
	}
}

int main() {
	static char cc[N + 1];
	static int ii[K];
	int n, k, h, i, b, ans;

	scanf("%d%s", &n, cc);
	k = 0;
	for (i = 0; i < n; i++)
		if (cc[i] == 'x')
			ii[k++] = i;
	ans = 0;
	for (b = 0; b < 1 << k; b++) {
		for (h = 0; h < k; h++)
			cc[ii[h]] = (b & 1 << h) == 0 ? '(' : ')';
		if (solve(cc, n))
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

securitygate.c: In function 'main':
securitygate.c:63:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  scanf("%d%s", &n, cc);
      |  ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 284 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 284 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 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 0 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 284 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 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 0 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 6 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 139 ms 264 KB Output is correct
35 Correct 5 ms 212 KB Output is correct
36 Correct 11 ms 280 KB Output is correct
37 Correct 67 ms 272 KB Output is correct
38 Correct 241 ms 336 KB Output is correct
39 Correct 5 ms 212 KB Output is correct
40 Correct 312 ms 264 KB Output is correct
41 Correct 322 ms 264 KB Output is correct
42 Correct 259 ms 260 KB Output is correct
43 Correct 162 ms 264 KB Output is correct
44 Correct 21 ms 276 KB Output is correct
45 Correct 333 ms 264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 284 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 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 0 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 6 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 139 ms 264 KB Output is correct
35 Correct 5 ms 212 KB Output is correct
36 Correct 11 ms 280 KB Output is correct
37 Correct 67 ms 272 KB Output is correct
38 Correct 241 ms 336 KB Output is correct
39 Correct 5 ms 212 KB Output is correct
40 Correct 312 ms 264 KB Output is correct
41 Correct 322 ms 264 KB Output is correct
42 Correct 259 ms 260 KB Output is correct
43 Correct 162 ms 264 KB Output is correct
44 Correct 21 ms 276 KB Output is correct
45 Correct 333 ms 264 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Runtime error 1 ms 340 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 284 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 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 280 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 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 0 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 6 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 139 ms 264 KB Output is correct
35 Correct 5 ms 212 KB Output is correct
36 Correct 11 ms 280 KB Output is correct
37 Correct 67 ms 272 KB Output is correct
38 Correct 241 ms 336 KB Output is correct
39 Correct 5 ms 212 KB Output is correct
40 Correct 312 ms 264 KB Output is correct
41 Correct 322 ms 264 KB Output is correct
42 Correct 259 ms 260 KB Output is correct
43 Correct 162 ms 264 KB Output is correct
44 Correct 21 ms 276 KB Output is correct
45 Correct 333 ms 264 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Runtime error 1 ms 340 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -