답안 #537595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537595 2022-03-15T09:27:38 Z tqbfjotld Security Gate (JOI18_security_gate) C++14
12 / 100
5000 ms 300 KB
#include <bits/stdc++.h>
using namespace std;

bool checkbr(vector<bool> s){
    int t = 0;
    for (int x = 0; x<s.size(); x++){
        if (s[x]) t++;
        else t--;
        if (t<0) return false;
    }
    return t==0;
}

bool valid(string s){
    //printf("checking %s\n",s.c_str());
    vector<int> pref;
    for (int x = 0; x<s.size(); x++){
        if (s[x]=='(')
            pref.push_back(1);
        else pref.push_back(-1);
        if (pref.size()>1){
            pref.back() = (*----pref.end()) + pref.back();
        }

    }
    int cc = pref.back();
    if (cc&1) return false;
    if (cc==0){
        vector<bool>tt;
        for (int x = 0; x<s.size(); x++){
            tt.push_back(s[x]=='(');
        }
        if (checkbr(tt))return true;
    }
    for (int st = 0; st<s.size(); st++){
        for (int en = st; en<s.size(); en++){
            int t2 = cc - 2*(pref[en]-(st==0?0:pref[st-1]));
            if (t2!=0) continue;
            else{
                vector<bool> tt;
                for (int x = 0; x<st; x++){
                    tt.push_back(s[x]=='(');
                }
                for (int x = st; x<=en; x++){
                    tt.push_back(s[x]==')');
                }
                for (int x = en+1; x<s.size(); x++){
                    tt.push_back(s[x]=='(');
                }
                if (checkbr(tt)){
                    return true;
                }
            }
        }
    }
    return false;
}

string str;
int ans = 0;

 main(){
    int n;
    scanf("%d",&n);
    str.resize(n);
    vector<int> pos;
    for (int x = 0; x<n; x++){
        scanf(" %c",&str[x]);
        if (str[x]=='x') pos.push_back(x);
    }
    for (int x = 0; x<(1<<(pos.size())); x++){
        for (int y = 0; y<pos.size(); y++){
            str[pos[y]] = (x&(1<<y))?'(':')';
        }
        if (valid(str)){
            ans++;
        }
    }
    printf("%d",ans);
}

Compilation message

securitygate.cpp: In function 'bool checkbr(std::vector<bool>)':
securitygate.cpp:6:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int x = 0; x<s.size(); x++){
      |                     ~^~~~~~~~~
securitygate.cpp: In function 'bool valid(std::string)':
securitygate.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int x = 0; x<s.size(); x++){
      |                     ~^~~~~~~~~
securitygate.cpp:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int x = 0; x<s.size(); x++){
      |                         ~^~~~~~~~~
securitygate.cpp:35:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int st = 0; st<s.size(); st++){
      |                      ~~^~~~~~~~~
securitygate.cpp:36:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int en = st; en<s.size(); en++){
      |                           ~~^~~~~~~~~
securitygate.cpp:47:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 for (int x = en+1; x<s.size(); x++){
      |                                    ~^~~~~~~~~
securitygate.cpp: At global scope:
securitygate.cpp:62:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 |  main(){
      |  ^~~~
securitygate.cpp: In function 'int main()':
securitygate.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int y = 0; y<pos.size(); y++){
      |                         ~^~~~~~~~~~~
securitygate.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
securitygate.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf(" %c",&str[x]);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 5 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 288 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 5 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 288 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 300 KB Output is correct
19 Correct 46 ms 212 KB Output is correct
20 Correct 56 ms 212 KB Output is correct
21 Correct 536 ms 280 KB Output is correct
22 Correct 210 ms 280 KB Output is correct
23 Correct 96 ms 272 KB Output is correct
24 Correct 771 ms 276 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 11 ms 296 KB Output is correct
27 Correct 242 ms 280 KB Output is correct
28 Correct 23 ms 272 KB Output is correct
29 Correct 8 ms 212 KB Output is correct
30 Correct 14 ms 212 KB Output is correct
31 Correct 210 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 5 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 288 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 300 KB Output is correct
19 Correct 46 ms 212 KB Output is correct
20 Correct 56 ms 212 KB Output is correct
21 Correct 536 ms 280 KB Output is correct
22 Correct 210 ms 280 KB Output is correct
23 Correct 96 ms 272 KB Output is correct
24 Correct 771 ms 276 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 11 ms 296 KB Output is correct
27 Correct 242 ms 280 KB Output is correct
28 Correct 23 ms 272 KB Output is correct
29 Correct 8 ms 212 KB Output is correct
30 Correct 14 ms 212 KB Output is correct
31 Correct 210 ms 288 KB Output is correct
32 Correct 289 ms 280 KB Output is correct
33 Correct 110 ms 212 KB Output is correct
34 Execution timed out 5049 ms 212 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 5 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 288 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 300 KB Output is correct
19 Correct 46 ms 212 KB Output is correct
20 Correct 56 ms 212 KB Output is correct
21 Correct 536 ms 280 KB Output is correct
22 Correct 210 ms 280 KB Output is correct
23 Correct 96 ms 272 KB Output is correct
24 Correct 771 ms 276 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 11 ms 296 KB Output is correct
27 Correct 242 ms 280 KB Output is correct
28 Correct 23 ms 272 KB Output is correct
29 Correct 8 ms 212 KB Output is correct
30 Correct 14 ms 212 KB Output is correct
31 Correct 210 ms 288 KB Output is correct
32 Correct 289 ms 280 KB Output is correct
33 Correct 110 ms 212 KB Output is correct
34 Execution timed out 5049 ms 212 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 5 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 288 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 300 KB Output is correct
19 Correct 46 ms 212 KB Output is correct
20 Correct 56 ms 212 KB Output is correct
21 Correct 536 ms 280 KB Output is correct
22 Correct 210 ms 280 KB Output is correct
23 Correct 96 ms 272 KB Output is correct
24 Correct 771 ms 276 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 11 ms 296 KB Output is correct
27 Correct 242 ms 280 KB Output is correct
28 Correct 23 ms 272 KB Output is correct
29 Correct 8 ms 212 KB Output is correct
30 Correct 14 ms 212 KB Output is correct
31 Correct 210 ms 288 KB Output is correct
32 Correct 289 ms 280 KB Output is correct
33 Correct 110 ms 212 KB Output is correct
34 Execution timed out 5049 ms 212 KB Time limit exceeded
35 Halted 0 ms 0 KB -