Submission #420478

# Submission time Handle Problem Language Result Execution time Memory
420478 2021-06-08T11:43:47 Z ACmachine Security Gate (JOI18_security_gate) C++17
12 / 100
5000 ms 296 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i-=(l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
typedef long long ll;
const int mod = (int)1e9 + 7;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int m = 0; 
    REP(i, s.length()){
        if(s[i] == 'x')
            m++;
    }
    int ans = 0;
    string ns;
    vector<int> min_suf(n + 1);
    vector<int> bal_suf(n + 1);
    auto check = [&](string s){
        int bal = 0;
        min_suf[n] = bal_suf[n] = 0;
        REPD(i, n - 1){
            if(s[i] == '(')
                bal++;
            else
                bal--;
            bal_suf[i] = bal;
            int up = (i == n - 1 ? 0 : min_suf[i + 1]);
            min_suf[i] = (s[i] == '(' ? 1 + up : up - 1);
            min_suf[i] = min(min_suf[i], 0);
        }
        bal = 0;
        if(min_suf[0] >= 0 && bal_suf[0] == 0) 
            return true;
        int mini = 0;
        REP(i, n){
            int nbal = bal;
            int nmini = mini;
            FOR(j, i, n, 1){
                nbal += (s[j] == '(' ? -1 : 1);
                nmini = min(nmini, nbal);
                if(nmini < 0) break;
                if(nbal + bal_suf[j + 1] == 0 && min_suf[j + 1] + nbal >= 0) 
                    return true;
            }
            bal += (s[i] == '(' ? 1 : -1);
            mini = min(mini, bal);  
            if(mini < 0)
                return false;
        }
        return false;
    };
    REP(mask, (1 << m)){
        ns = s; 
        int curr = 0;
        REP(j, n){
            if(ns[j] == 'x'){
                if(mask & (1 << curr))
                    ns[j] = '('; 
                else
                    ns[j] = ')';
                curr++;
            }
        }
        if(check(ns)){
            ans++;
        }
    }
    cout << ans << "\n";
}

Compilation message

securitygate.cpp: In function 'int main()':
securitygate.cpp:3:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
securitygate.cpp:5:19: note: in expansion of macro 'FOR'
    5 | #define REP(i, n) FOR(i, 0, n, 1)
      |                   ^~~
securitygate.cpp:14:5: note: in expansion of macro 'REP'
   14 |     REP(i, s.length()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 6 ms 204 KB Output is correct
22 Correct 9 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 7 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 7 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 6 ms 204 KB Output is correct
22 Correct 9 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 7 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 7 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
32 Correct 18 ms 204 KB Output is correct
33 Correct 5 ms 204 KB Output is correct
34 Correct 338 ms 272 KB Output is correct
35 Correct 16 ms 204 KB Output is correct
36 Correct 42 ms 272 KB Output is correct
37 Correct 203 ms 284 KB Output is correct
38 Execution timed out 5041 ms 204 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 6 ms 204 KB Output is correct
22 Correct 9 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 7 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 7 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
32 Correct 18 ms 204 KB Output is correct
33 Correct 5 ms 204 KB Output is correct
34 Correct 338 ms 272 KB Output is correct
35 Correct 16 ms 204 KB Output is correct
36 Correct 42 ms 272 KB Output is correct
37 Correct 203 ms 284 KB Output is correct
38 Execution timed out 5041 ms 204 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 6 ms 204 KB Output is correct
22 Correct 9 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 7 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 7 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 4 ms 204 KB Output is correct
32 Correct 18 ms 204 KB Output is correct
33 Correct 5 ms 204 KB Output is correct
34 Correct 338 ms 272 KB Output is correct
35 Correct 16 ms 204 KB Output is correct
36 Correct 42 ms 272 KB Output is correct
37 Correct 203 ms 284 KB Output is correct
38 Execution timed out 5041 ms 204 KB Time limit exceeded
39 Halted 0 ms 0 KB -