이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define Maxn 100009
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> order;
bool d;
int P, T;
string s, s1, ans;
void func (int pos, int sz) {
if (pos == sz) {
int a = 0, b = 0;
for (int i = 0; i < sz; i++) {
if (s[i] == '(') {
if (s1[i] == 'B')
a ++;
else if (s1[i] == 'R')
b ++;
else
a ++, b ++;
}
else {
if (s1[i] == 'B')
a --;
else if (s1[i] == 'R')
b --;
else
a --, b --;
if (a < 0 or b < 0)
break;
}
}
if (a == 0 and b == 0) {
d = 1;
if (ans[0] == '(')
ans = s1;
}
return;
}
s1[pos] = 'R';
func (pos + 1, sz);
s1[pos] = 'B';
func (pos + 1, sz);
s1[pos] = 'G';
func (pos + 1, sz);
}
int main () {
//freopen ("file.in", "r", stdin);
//freopen ("file.out", "w", stdout);
//srand ((unsigned) time ( NULL ));
//int randomNumber = rand() % 10 + 1;
scanf ("%d%d", &P, &T);
if (P == 1) {
for (int i = 1; i <= T; i++) {
d = 0;
cin >> s;
int sz = s.size();
s1.clear();
ans = s;
s1 = s;
func (0, sz);
if (d)
cout << ans << '\n';
else
puts ("impossible");
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
parentrises.cpp: In function 'int main()':
parentrises.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &P, &T);
~~~~~~^~~~~~~~~~~~~~~~
# | 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... |