# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74106 | zscoder | parentrises (BOI18_parentrises) | C++17 | 3 ms | 712 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>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int ans[1111111];
bool solve(string &s)
{
int n=s.length();
for(int i=0;i<n;i++) ans[i]=0;
int ptr = 0;
stack<int> S;
for(int i=0;i<n;i++)
{
if(s[i]=='(')
{
S.push(i);
}
else
{
if(!S.empty())
{
int u=S.top();
ans[i]|=1; ans[u]|=1; S.pop();
}
else
{
while(ptr<i&&(s[ptr]!='('||ans[ptr]>=3)) ptr++;
if(ptr>=i) return 0;
ans[ptr]|=2; ans[i]|=2;
}
}
}
ptr=n-1;
for(int i=n-1;i>=0;i--)
{
if(s[i]==')'||ans[i]>0) continue;
while(ptr>i&&(s[ptr]!=')'||ans[ptr]>=3)) ptr--;
ans[i]|=2; ans[ptr]|=2;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int type; cin>>type;
int t; cin>>t;
while(t--)
{
if(type==1)
{
string s; cin>>s;
bool tmp = solve(s);
if(!tmp)
{
cout<<"impossible\n";
continue;
}
for(int i=0;i<s.length();i++)
{
if(ans[i]==1) cout<<"B";
else if(ans[i]==2) cout<<"R";
else cout<<"G";
}
cout<<'\n';
}
else
{
int n; cin>>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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |