Submission #1038881

#TimeUsernameProblemLanguageResultExecution timeMemory
1038881marparentrises (BOI18_parentrises)C++14
50 / 100
109 ms5196 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
signed main(){
    int p,t;
    cin>>p>>t;
    if(p==1){
        while(t--){
            string s,ans="";
            cin>>s;
            stack<int> st;
            for(int i=0; i<s.size(); i++){
                ans+='.';
            }
            for(int i=0; i<s.size(); i++){
                if(s[i]=='(') {
                    st.push(i);
                }else{
                    if(st.size()!=0){
                        ans[st.top()]='R';
                        ans[i]='R';
                        st.pop();
                    }
                }
            }
            while(st.size()!=0) st.pop();
            for(int i=0; i<s.size(); i++){
                if(s[i]=='(' && ans[i]=='.') st.push(i);
                else if(s[i]==')'){
                    if(st.size()!=0){
                        ans[st.top()]='B';
                        ans[i]='G';
                        st.pop();
                    }
                }
            }
            while(st.size()!=0) st.pop();
            for(int i=s.size()-1; i>=0; i--){
                if(s[i]==')' && ans[i]=='.')st.push(i);
                else if(s[i]=='(' && ans[i]=='R'){
                    if(st.size()!=0){
                        ans[st.top()]='B';
                        ans[i]='G';
                        st.pop();
                    }
                }
            }
            bool flag=true;
            for(int i=0; i<ans.size(); i++){
                if(ans[i]=='.')flag=false;
            }
            if(flag) cout<<ans<<endl;
            else cout<<"impossible\n";
        }
    }
}

Compilation message (stderr)

parentrises.cpp: In function 'int main()':
parentrises.cpp:14:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |             for(int i=0; i<s.size(); i++){
      |                          ~^~~~~~~~~
parentrises.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             for(int i=0; i<s.size(); i++){
      |                          ~^~~~~~~~~
parentrises.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             for(int i=0; i<s.size(); i++){
      |                          ~^~~~~~~~~
parentrises.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int i=0; i<ans.size(); i++){
      |                          ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...