Submission #423713

#TimeUsernameProblemLanguageResultExecution timeMemory
423713egekabasparentrises (BOI18_parentrises)C++14
50 / 100
59 ms7276 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; void solve1(){ string s; cin >> s; int n = s.size(); int cur = 0; int mini = 0; for(int i = 0; i < n; ++i){ if(s[i] == '(') cur++; else cur--; mini = min(mini, cur); } vector<int> ans(n); mini *= -1; for(int i = 0; i < n; ++i){ if(mini > 0 && s[i] == '('){ ans[i] = 1; --mini; ++cur; } } if(mini > 0){ cout << "impossible\n"; return; } for(int i = n-1; i >= 0; --i){ if(s[i] == '(') continue; if(cur > 0){ ans[i] = 1; --cur; } } if(cur > 0){ cout << "impossible\n"; return; } cur = 0; for(int i = 0; i < n; ++i){ if(s[i] == '(') cur++; else cur--; if(ans[i]){ if(s[i] == '(') cur++; else cur--; } if(cur < 0){ cout << "impossible\n"; return; } } int val[2] = {0, 0}; char c[3] = {'R', 'B', 'G'}; for(int i = 0; i < n; ++i){ //cout << '\n' << val[0] << ' ' << val[1] << '\n'; if(ans[i]){ cout << c[2]; if(s[i] == '('){ ++val[0]; ++val[1]; } else{ --val[0]; --val[1]; } } else{ if(s[i] == '('){ if(val[0] < val[1]){ ++val[0]; cout << c[0]; } else{ ++val[1]; cout << c[1]; } } else{ if(val[0] > val[1]){ --val[0]; cout << c[0]; } else{ --val[1]; cout << c[1]; } } } } cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int p; cin >> p; if(p == 1){ int t; cin >> t; while(t--) solve1(); } }
#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...