# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170742 | 2019-12-26T08:58:16 Z | dndhk | parentrises (BOI18_parentrises) | C++14 | 253 ms | 19308 KB |
#include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define sortv(v) sort(all(v)) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define pb push_back #define FI first #define SE second #define lb lower_bound #define ub upper_bound #define mp make_pair #define test 1 #define TEST if(test) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; const int MOD = 1000000007; // 998244353 const int INF = 2e9; const ll INFLL = 1e18; const int MAX_N = 1; int P, T; string str; vector<pii> vt; vector<int> ans; int main(){ scanf("%d%d", &P, &T); if(P==1){ while(T--){ bool tf = true; while(!vt.empty()) vt.pop_back(); cin>>str; if(str[0]==')'){ printf("impossible\n"); continue; } vt.pb({1, 2}); for(int i=1; i<str.size(); i++){ pii prv = vt.back(); if(str[i]=='('){ prv.first++; prv.second+=2; }else{ prv.first-=2; prv.second--; } if(prv.second<0){ tf = false; break; } prv.first = max(prv.first, 0); vt.pb(prv); } if(vt.back().first!=0){ tf = false; } if(!tf){ printf("impossible\n"); }else{ int num1=0, num2=0; int n = 0; for(int i=str.size()-1; i>=0; i--){ pii now = vt[i]; vt.pop_back(); if(vt.empty()){ if(n==2){ ans.pb(3); }else{ if(num1>0) ans.pb(1); else ans.pb(2); } }else{ if(str[i]=='('){ if(vt.back().first<=n-1 && n-1<=vt.back().second){ if(num1<num2){ ans.pb(2); num2--; }else{ ans.pb(1); num1--; } n--; }else{ ans.pb(3); num1--; num2--; n-=2; } }else{ if(vt.back().first<=n+1 && n+1<=vt.back().second){ if(num1>num2){ ans.pb(2); num2++; }else{ ans.pb(1); num1++; } n++; }else{ ans.pb(3); num1++; num2++; n+=2; } } } } while(!ans.empty()){ if(ans.back()==3){ printf("G"); }else if(ans.back()==2){ printf("B"); }else{ printf("R"); } ans.pop_back(); } printf("\n"); } } }else{ } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 248 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 248 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 504 KB | Output is correct |
12 | Correct | 4 ms | 540 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 632 KB | Output is correct |
16 | Correct | 32 ms | 504 KB | Output is correct |
17 | Correct | 16 ms | 2412 KB | Output is correct |
18 | Correct | 12 ms | 760 KB | Output is correct |
19 | Correct | 13 ms | 1492 KB | Output is correct |
20 | Correct | 16 ms | 2412 KB | Output is correct |
21 | Correct | 253 ms | 2148 KB | Output is correct |
22 | Correct | 140 ms | 19124 KB | Output is correct |
23 | Correct | 99 ms | 3972 KB | Output is correct |
24 | Correct | 115 ms | 10572 KB | Output is correct |
25 | Correct | 142 ms | 19308 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Unexpected end of file - int32 expected |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Unexpected end of file - int32 expected |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Unexpected end of file - int32 expected |