Submission #1090591

# Submission time Handle Problem Language Result Execution time Memory
1090591 2024-09-18T13:33:11 Z noyancanturk parentrises (BOI18_parentrises) C++17
50 / 100
96 ms 10060 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

const int lim=5e5+100;

void solve1(){
  string s;
  cin>>s;
  int n=s.size();
  int ty[n]{};
  int haveemp=0;
  vector<int>pools[2];
  for(int i=0;i<n;i++){
    if(s[i]=='('){
      haveemp++;
    }else if(1<haveemp){
      pools[0].pb(i);
      haveemp-=2;
    }else if(haveemp){
      pools[1].pb(i);
      ty[i]=1;
      haveemp=0;
    }else if(pools[0].size()){
      int toconvert=pools[0].back();
      pools[0].pop_back();
      ty[toconvert]=ty[i]=1;
      pools[1].pb(i);
      pools[1].pb(toconvert);
    }else if(pools[1].size()){
      int toconvert=pools[1].back();
      pools[1].pop_back();
      ty[i]=2;
      ty[toconvert]=3;
    }else{
      cout<<"impossible\n";
      return;
    }
  }
  if(haveemp){
    cout<<"impossible\n";
    return;
  }
  int needgreen=0,needred=0,needblue=0;
  string ans=string(n,' ');
  for(int i=n-1;0<=i;i--){
    if(s[i]=='('){
      if(needgreen){
        ans[i]='G';
        needgreen--;
      }else if(needred){
        ans[i]='R';
        needred--;
      }else if(needblue){
        ans[i]='B';
        needblue--;
      }
    }else if(ty[i]==0){
      ans[i]='G';
      needred++,needblue++;
    }else if(ty[i]==1){
      ans[i]='G';
      needgreen++;
    }else if(ty[i]==2){
      ans[i]='B';
    }else{
      ans[i]='R';
      needgreen++;
    }
  }
  cout<<ans<<"\n"; 
}
void solve2(){}

int main(){
  #ifdef Local
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
  #endif
  int _;
  cin>>_;
  if(_==1){
    int t;
    cin>>t;
    while(t--)solve1();
  }else{
    int t;
    cin>>t;
    while(t--)solve2();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 11 ms 604 KB Output is correct
17 Correct 3 ms 1476 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 928 KB Output is correct
20 Correct 4 ms 1496 KB Output is correct
21 Correct 96 ms 2132 KB Output is correct
22 Correct 34 ms 10060 KB Output is correct
23 Correct 19 ms 3100 KB Output is correct
24 Correct 24 ms 5408 KB Output is correct
25 Correct 28 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -