답안 #56701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56701 2018-07-12T08:19:49 Z 강태규(#1615) Security Gate (JOI18_security_gate) C++11
12 / 100
5000 ms 920 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int mod = 1e9 + 7;
int n;
char str[301];
int val[301];
int sum[301];
int mx[301][301];
int mn[301][301];

int pro(int x) {
    if (x == n) {
        for (int i = 0; i < n; ++i) {
            sum[i + 1] = sum[i] + val[i];
        }
        for (int i = 0; i <= n; ++i) {
            mx[i][i] = mn[i][i] = sum[i];
            for (int j = i + 1; j <= n; ++j) {
                mx[i][j] = max(mx[i][j - 1], sum[j]);
                mn[i][j] = min(mn[i][j - 1], sum[j]);
            }
        }
        
        if (sum[n] == 0 && 0 <= mn[0][n]) return 1;
        for (int i = 0; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (2 * (sum[j] - sum[i]) != sum[n]) continue;
                if (mn[0][i] < 0) continue;
                if (mn[j][n] < sum[n]) continue;
                if (2 * sum[i] < mx[i][j]) continue;
                return 1;
            }
        }
        return 0;
    }
    if (val[x] != 0) return pro(x + 1);
    val[x] = -1;
    int ret = pro(x + 1);
    val[x] = 1;
    ret += pro(x + 1);
    val[x] = 0;
    return ret;
}

int main() {
    scanf("%d%s", &n, str);
    if (n & 1) {
        printf("0\n");
        return 0;   
    }
    for (int i = 0; i < n; ++i) {
        switch (str[i]) {
        case '(':
            val[i] = 1;
            break;
        case ')':
            val[i] = -1;
            break;
        }
    }
    printf("%d\n", pro(0));
	return 0;
}

Compilation message

securitygate.cpp: In function 'int main()':
securitygate.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &n, str);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 3 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 3 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 3 ms 816 KB Output is correct
19 Correct 9 ms 816 KB Output is correct
20 Correct 10 ms 816 KB Output is correct
21 Correct 87 ms 876 KB Output is correct
22 Correct 84 ms 876 KB Output is correct
23 Correct 14 ms 876 KB Output is correct
24 Correct 81 ms 876 KB Output is correct
25 Correct 4 ms 876 KB Output is correct
26 Correct 6 ms 876 KB Output is correct
27 Correct 49 ms 876 KB Output is correct
28 Correct 10 ms 876 KB Output is correct
29 Correct 9 ms 876 KB Output is correct
30 Correct 4 ms 876 KB Output is correct
31 Correct 59 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 3 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 3 ms 816 KB Output is correct
19 Correct 9 ms 816 KB Output is correct
20 Correct 10 ms 816 KB Output is correct
21 Correct 87 ms 876 KB Output is correct
22 Correct 84 ms 876 KB Output is correct
23 Correct 14 ms 876 KB Output is correct
24 Correct 81 ms 876 KB Output is correct
25 Correct 4 ms 876 KB Output is correct
26 Correct 6 ms 876 KB Output is correct
27 Correct 49 ms 876 KB Output is correct
28 Correct 10 ms 876 KB Output is correct
29 Correct 9 ms 876 KB Output is correct
30 Correct 4 ms 876 KB Output is correct
31 Correct 59 ms 876 KB Output is correct
32 Correct 58 ms 876 KB Output is correct
33 Correct 20 ms 876 KB Output is correct
34 Correct 2614 ms 876 KB Output is correct
35 Correct 44 ms 876 KB Output is correct
36 Correct 1527 ms 912 KB Output is correct
37 Correct 4787 ms 912 KB Output is correct
38 Execution timed out 5064 ms 920 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 3 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 3 ms 816 KB Output is correct
19 Correct 9 ms 816 KB Output is correct
20 Correct 10 ms 816 KB Output is correct
21 Correct 87 ms 876 KB Output is correct
22 Correct 84 ms 876 KB Output is correct
23 Correct 14 ms 876 KB Output is correct
24 Correct 81 ms 876 KB Output is correct
25 Correct 4 ms 876 KB Output is correct
26 Correct 6 ms 876 KB Output is correct
27 Correct 49 ms 876 KB Output is correct
28 Correct 10 ms 876 KB Output is correct
29 Correct 9 ms 876 KB Output is correct
30 Correct 4 ms 876 KB Output is correct
31 Correct 59 ms 876 KB Output is correct
32 Correct 58 ms 876 KB Output is correct
33 Correct 20 ms 876 KB Output is correct
34 Correct 2614 ms 876 KB Output is correct
35 Correct 44 ms 876 KB Output is correct
36 Correct 1527 ms 912 KB Output is correct
37 Correct 4787 ms 912 KB Output is correct
38 Execution timed out 5064 ms 920 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 3 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 804 KB Output is correct
13 Correct 4 ms 804 KB Output is correct
14 Correct 3 ms 804 KB Output is correct
15 Correct 3 ms 804 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 3 ms 816 KB Output is correct
19 Correct 9 ms 816 KB Output is correct
20 Correct 10 ms 816 KB Output is correct
21 Correct 87 ms 876 KB Output is correct
22 Correct 84 ms 876 KB Output is correct
23 Correct 14 ms 876 KB Output is correct
24 Correct 81 ms 876 KB Output is correct
25 Correct 4 ms 876 KB Output is correct
26 Correct 6 ms 876 KB Output is correct
27 Correct 49 ms 876 KB Output is correct
28 Correct 10 ms 876 KB Output is correct
29 Correct 9 ms 876 KB Output is correct
30 Correct 4 ms 876 KB Output is correct
31 Correct 59 ms 876 KB Output is correct
32 Correct 58 ms 876 KB Output is correct
33 Correct 20 ms 876 KB Output is correct
34 Correct 2614 ms 876 KB Output is correct
35 Correct 44 ms 876 KB Output is correct
36 Correct 1527 ms 912 KB Output is correct
37 Correct 4787 ms 912 KB Output is correct
38 Execution timed out 5064 ms 920 KB Time limit exceeded
39 Halted 0 ms 0 KB -