제출 #407117

#제출 시각아이디문제언어결과실행 시간메모리
40711779brueSecurity Gate (JOI18_security_gate)C++14
30 / 100
5021 ms324 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
char s[102];
int pref[102];
int ans;

void dfs(int x){
    if(x == n+1){
        int firstNegative = 101, lastNegative = -1;
        for(int i=1; i<=n; i++) if(pref[i] < 0) firstNegative = min(firstNegative, i);
        for(int i=1; i<=n; i++) if(pref[i] - pref[n] < 0) lastNegative = i;

        if(pref[n] == 0 && lastNegative == -1){
            ans++;
            return;
        }

        bool able = 0;
        for(int i=1; i<=n && i<=firstNegative; i++){
            bool good = 0;
            for(int j=i; j<=n; j++){
                if(pref[j] > 2 * pref[i-1]) break;
                if(pref[n] - 2 * (pref[j] - pref[i-1]) == 0 && j > lastNegative){
                    good = 1;
                    break;
                }
            }
            if(good){
                able = 1;
                break;
            }
        }
        if(able) ans++;
        return;
    }
    if(s[x] == '(' || s[x] == ')'){
        pref[x] = pref[x-1] + (s[x] == '(' ? 1 : -1);
        dfs(x+1);
        return;
    }
    s[x] = '('; pref[x] = pref[x-1] + 1;
    dfs(x+1);
    s[x] = ')'; pref[x] = pref[x-1] - 1;
    dfs(x+1);
    s[x] = 'x';
    return;
}

int main(){
    scanf("%d %s", &n, s+1);
    if(n%2){
        printf("0");
        return 0;
    }
    dfs(1);
    printf("%d", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

securitygate.cpp: In function 'int main()':
securitygate.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d %s", &n, s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...