Submission #407116

#TimeUsernameProblemLanguageResultExecution timeMemory
40711679brueSecurity Gate (JOI18_security_gate)C++14
0 / 100
1 ms204 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; 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); }

Compilation message (stderr)

securitygate.cpp: In function 'int main()':
securitygate.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     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...