# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67842 | Good | parentrises (BOI18_parentrises) | C++11 | 3 ms | 500 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>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define Maxn 1000009
#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;
int P, T;
char s[Maxn];
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) {
string s1;
vector <pair <int, char> > v;
for (int i = 1; i <= T; i++) {
scanf ("%s", &s);
v.clear ();
s1.clear();
s1 = s;
int sz = strlen (s);
for (int j = 0; j < sz; j++) {
if (s[j] == '(')
v.pb ({j, '('});
else {
if (v.size() > 0 and v.back().ss == '(')
s1[v.back().ff] = 'B', s1[j] = 'B', v.ppb ();
else
v.pb ({j, ')'});
}
}
for (auto j: v) {
if (j.ss == '(') {
for (int k = sz - 1; k > j.ff; k--)
if (s[k] == ')' and s1[k] == 'B') {
s1[k] = 'G', s1[j.ff] = 'R';
break;
}
}
else {
for (int k = j.ff - 1; k >= 0; k--) {
if (s[k] == '(' and s1[k] == 'B') {
s1[k] = 'G', s1[j.ff] = 'R';
break;
}
}
}
}
bool d = 0;
for (int j = 0; j < sz; j++)
if (s1[j] == '(' or s1[j] == ')') {
d = 1;
break;
}
if (d)
puts ("impossible");
else
cout << s1 << '\n';
}
}
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |