# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
64326 | Just_Solve_The_Problem | parentrises (BOI18_parentrises) | C++11 | 1076 ms | 13484 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int b[N];
vector < int > stk;
int a[N];
int mod = (int)1e9 + 7;
bool solve1(string &s) {
b[0] = ((s[0] == '(') ? 1 : -1);
a[0] = 1;
for (int i = 1; i < sz(s); i++) {
b[i] = b[i - 1] + ((s[i] == '(') ? 1 : -1);
a[i] = 1;
}
int cur = 0;
stk.clear();
for (int i = 0; i < sz(s); i++) {
if (s[i] == ')') stk.pb(i);
if (b[i] + cur < 0) {
// cout << i << ' ' << b[i] + cur << ' ' << sz(stk) << endl;
while (b[i] + cur < 0 && sz(stk) > 1) {
a[stk.back()] = 0;
stk.pop_back();
a[stk.back()] = 2;
stk.pop_back();
cur++;
}
if (b[i] + cur < 0) {
return 0;
}
}
}
stk.clear();
for (int i = 0; i < sz(s); i++) {
if (s[i] == '(')
stk.pb(i);
}
int b1 = b[sz(s) - 1] + cur;
while (b1 > 0 && sz(stk) > 1) {
b1--;
a[stk.back()] = 0;
stk.pop_back();
a[stk.back()] = 2;
stk.pop_back();
}
if (b1 > 0) {
return 0;
}
b1 = 0;
int b2 = 0;
bool fl = 0;
for (int i = 0; i < sz(s); i++) {
if (a[i] <= 1) {
b1 += ((s[i] == '(') ? 1 : -1);
}
if (a[i] >= 1) {
b2 += ((s[i] == '(') ? 1 : -1);
}
fl |= (b1 < 0 || b2 < 0);
}
fl |= (b1 != 0 || b2 != 0);
if (fl) {
return 0;
}
return 1;
}
int add(int a, int b) {
return (a + b) % mod;
}
int n;
int ans = 0;
void go(string &s) {
if (sz(s) == n) {
if (solve1(s)) {
// cout << s << endl;
ans++;
}
return ;
}
s.pb('(');
go(s);
s.pop_back();
s.pb(')');
go(s);
s.pop_back();
}
void solve2() {
scanf("%d", &n);
string asd;
ans = 0;
go(asd);
cout << ans << endl;
}
main() {
int p;
scanf("%d", &p);
int test;
scanf("%d", &test);
if (p == 1) {
while (test--) {
string s;
cin >> s;
if (solve1(s) == 0) {
puts("impossible");
} else {
for (int i = 0; i < sz(s); i++) {
if (a[i] == 0) printf("R");
else if (a[i] == 1) printf("G");
else printf("B");
}
puts("");
}
}
} else {
while (test--)
solve2();
}
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |