QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#543019 | #7683. Hard Brackets Problem | mhw# | WA | 17ms | 3968kb | C++23 | 1.5kb | 2024-09-01 12:50:14 | 2024-09-01 12:50:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
const ll inf = 1145141919810;
using namespace std;
inline ll read() {
ll x=0,f=1;
char c=getchar();
while (c<'0' || c>'9') {
if (c=='-') f=-1;
c=getchar();
}
while (c>='0' && c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
inline void print(ll x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + '0');
return ;
}
inline void pprint(ll x) {
print(x);
puts("");
}
const int N = 2e6 + 7;
char s[N];
void slv() {
vector<char> t;
scanf("%s", s + 1);
int n = strlen(s + 1);
int st = 0;
rep(i, 1, n) {
if(s[i] == '(') {
st = i;
break;
} else {
t.pb(')');
}
}
int tot = 0;
ll l = -1, r = -inf;
while(st <= n) {
// cout << "st = " << st << endl;
tot = 0;
//往右暴力扩展左括号
rep(j, st, n) {
if(s[j] == '(') l = j;
else break;
}
rep(j, l + 1, n) {
if(s[j] == ')') r = j;
}
// cout << "l = " << l << ", r = " << r << endl;
if(l - st + 1 <= r - l) {
rep(k, 1, l - st + 1) {
t.pb('(');
}
rep(k, 1, l - st + 1) {
t.pb(')');
}
rep(k, 1, r - l - (l - st + 1)) {
t.pb(')');
}
} else {
puts("impossible");
return ;
}
st = r + 1;
}
for(auto x:t){
putchar(x);
}
puts("");
}
int main() {
int T = read();
while(T--) {
slv();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
3 ((())) ( )))()
output:
((())) impossible )))()
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 17ms
memory: 3968kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
())))))))) ()))))))) )())))))) impossible ((()))))) impossible )()))))))) impossible impossible ())))))))) (())))))) ())))))))) (()))))))) ))))(()))) impossible ())))))))) ())))))))) ())))))))) ())))))))) ()))))))) (())))))) ()))))))) ())))))))) (())))))) ())))))))) impossible ((((())))) (()))))))) ...
result:
wrong answer the result string is incorrect (test case 1)