Submission #56712

# Submission time Handle Problem Language Result Execution time Memory
56712 2018-07-12T08:37:38 Z 강태규(#1615) Security Gate (JOI18_security_gate) C++11
30 / 100
5000 ms 736 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 f[301];

int imax(int x, int y) {
    return x < y ? y : x;
}

const int sz = 1 << 9;
int seg[sz << 1];
void init() {
    for (int i = 0; i <= n; ++i) seg[i + sz] = sum[i];
    for (int i = sz; --i; ) seg[i] = imax(seg[i << 1], seg[i << 1 | 1]);
}

int query(int i, int j) {
    int ret = -1000;
    i += sz;
    j += sz;
    while (i <= j) {
        ret = imax(ret, seg[i]);
        ret = imax(ret, seg[j]);
        i = (i + 1) >> 1;
        j = (j - 1) >> 1;
    }
    return ret;
}

int pro(int x) {
    if (x == n) {
        for (int i = 0; i < n; ++i) {
            sum[i + 1] = sum[i] + val[i];
        }
        init();
        int mxi = n + 1, mnj = -1;
        
        for (int i = n + 1; i--; ) {
            if (sum[i] < 0) mxi = i;
        }
        for (int i = 0; i <= n; ++i) {
            if (sum[i] < sum[n]) mnj = i;
        }
        for (int i = 0; i <= n; ++i) f[i] = -1;
        int bt = 0, tp = 0;
        for (int j = mnj + 1, i = 0; j <= n; ++j) {
            while (i < mxi && i <= j) {
                f[sum[i]] = i;
                ++i;
            }
            int s = sum[j] - sum[n] / 2;
            if (s < 0) continue;
            if (s > n) continue;
            if (f[s] == -1) continue;
            if (2 * s < query(f[s], 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 pro(int)':
securitygate.cpp:67:13: warning: unused variable 'bt' [-Wunused-variable]
         int bt = 0, tp = 0;
             ^~
securitygate.cpp:67:21: warning: unused variable 'tp' [-Wunused-variable]
         int bt = 0, tp = 0;
                     ^~
securitygate.cpp: In function 'int main()':
securitygate.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%s", &n, str);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 5 ms 716 KB Output is correct
21 Correct 10 ms 716 KB Output is correct
22 Correct 9 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 7 ms 716 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 7 ms 716 KB Output is correct
28 Correct 5 ms 716 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 8 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 5 ms 716 KB Output is correct
21 Correct 10 ms 716 KB Output is correct
22 Correct 9 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 7 ms 716 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 7 ms 716 KB Output is correct
28 Correct 5 ms 716 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 8 ms 716 KB Output is correct
32 Correct 55 ms 716 KB Output is correct
33 Correct 17 ms 716 KB Output is correct
34 Correct 1223 ms 716 KB Output is correct
35 Correct 56 ms 716 KB Output is correct
36 Correct 68 ms 716 KB Output is correct
37 Correct 309 ms 716 KB Output is correct
38 Correct 1307 ms 716 KB Output is correct
39 Correct 60 ms 716 KB Output is correct
40 Correct 1192 ms 716 KB Output is correct
41 Correct 1096 ms 716 KB Output is correct
42 Correct 1157 ms 716 KB Output is correct
43 Correct 661 ms 716 KB Output is correct
44 Correct 83 ms 716 KB Output is correct
45 Correct 1110 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 5 ms 716 KB Output is correct
21 Correct 10 ms 716 KB Output is correct
22 Correct 9 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 7 ms 716 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 7 ms 716 KB Output is correct
28 Correct 5 ms 716 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 8 ms 716 KB Output is correct
32 Correct 55 ms 716 KB Output is correct
33 Correct 17 ms 716 KB Output is correct
34 Correct 1223 ms 716 KB Output is correct
35 Correct 56 ms 716 KB Output is correct
36 Correct 68 ms 716 KB Output is correct
37 Correct 309 ms 716 KB Output is correct
38 Correct 1307 ms 716 KB Output is correct
39 Correct 60 ms 716 KB Output is correct
40 Correct 1192 ms 716 KB Output is correct
41 Correct 1096 ms 716 KB Output is correct
42 Correct 1157 ms 716 KB Output is correct
43 Correct 661 ms 716 KB Output is correct
44 Correct 83 ms 716 KB Output is correct
45 Correct 1110 ms 724 KB Output is correct
46 Correct 3 ms 728 KB Output is correct
47 Correct 3 ms 728 KB Output is correct
48 Correct 2 ms 736 KB Output is correct
49 Execution timed out 5002 ms 736 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 668 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 3 ms 716 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 2 ms 716 KB Output is correct
16 Correct 2 ms 716 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 5 ms 716 KB Output is correct
21 Correct 10 ms 716 KB Output is correct
22 Correct 9 ms 716 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 7 ms 716 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 7 ms 716 KB Output is correct
28 Correct 5 ms 716 KB Output is correct
29 Correct 3 ms 716 KB Output is correct
30 Correct 3 ms 716 KB Output is correct
31 Correct 8 ms 716 KB Output is correct
32 Correct 55 ms 716 KB Output is correct
33 Correct 17 ms 716 KB Output is correct
34 Correct 1223 ms 716 KB Output is correct
35 Correct 56 ms 716 KB Output is correct
36 Correct 68 ms 716 KB Output is correct
37 Correct 309 ms 716 KB Output is correct
38 Correct 1307 ms 716 KB Output is correct
39 Correct 60 ms 716 KB Output is correct
40 Correct 1192 ms 716 KB Output is correct
41 Correct 1096 ms 716 KB Output is correct
42 Correct 1157 ms 716 KB Output is correct
43 Correct 661 ms 716 KB Output is correct
44 Correct 83 ms 716 KB Output is correct
45 Correct 1110 ms 724 KB Output is correct
46 Correct 3 ms 728 KB Output is correct
47 Correct 3 ms 728 KB Output is correct
48 Correct 2 ms 736 KB Output is correct
49 Execution timed out 5002 ms 736 KB Time limit exceeded
50 Halted 0 ms 0 KB -