# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
420478 | ACmachine | Security Gate (JOI18_security_gate) | C++17 | 5041 ms | 296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
컴파일 시 표준 에러 (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... |