# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57713 | ksun48 | Security Gate (JOI18_security_gate) | C++14 | 5009 ms | 1008 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL check(string s){
vector<int> psums(1,0);
for(int j = 0; j < s.size(); j++){
if(s[j] == '('){
psums.push_back(psums[psums.size() - 1] + 1);
} else {
psums.push_back(psums[psums.size() - 1] - 1);
}
}
int laste = psums.size() - 1;
while(laste > 0 && psums[laste-1] >= psums[psums.size()-1]){
laste--;
}
map<int,vector<int> > endlists;
for(int j = laste; j <= psums.size() - 1; j++){
endlists[psums[j]].push_back(j);
}
int a = psums[psums.size() - 1] / 2;
for(int j = 0; j < psums.size(); j++){
if(psums[j] < 0) break;
int need = psums[j] + a;
vector<int>& z = endlists[need];
int idx = lower_bound(z.begin(), z.end(), j) - z.begin();
if(idx >= z.size()) continue;
int e = z[idx];
// check if all elements in [j,e] are <=
int ok = 1;
for(int i = j; i <= e; i++){
if(psums[i] > 2 * psums[j]){
ok = 0;
break;
}
}
if(ok){
return 1;
}
}
return 0;
}
LL cnt(string s, int idx){
if(idx == s.size()) return check(s);
if(s[idx] != 'x'){
return cnt(s, idx + 1);
}
string s1 = s;
string s2 = s;
s1[idx] = '(';
s2[idx] = ')';
return (cnt(s1, idx + 1) + cnt(s2, idx + 1)) % MOD;
}
int main(){
int n;
string s;
cin >> n >> s;
if(n % 2 == 1){
cout << 0 << '\n';
return 0;
}
cout << cnt(s, 0) << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |