QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287191 | #7683. Hard Brackets Problem | Detach | WA | 23ms | 3544kb | C++17 | 1.2kb | 2023-12-19 22:25:55 | 2023-12-19 22:25:56 |
Judging History
answer
#include <bits/stdc++.h>
// #include <algorithm>
// #include <queue>
// #include <map>
// #include <iostream>
// #include <string>
// #include <set>
#define endl '\n'
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using i128 = __int128_t;
using ULL = unsigned long long;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, N = 1e6 + 5;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
void solve()
{
string s;
cin >> s;
int n = s.size(), cnt[2] = {0};
for(int i = 0; i < n; i ++ )
{
int k;
if(s[i] == '(') cnt[0] ++ ;
else cnt[1] ++ ;
}
if(cnt[0] > cnt[1])
{
cout << "impossible" << endl;
}
else
{
int now = 0;
for(int i = 0; i < n; i ++ )
{
if(now == cnt[1]) break;
cout << s[i];
if(s[i] == '(') now ++ ;
else if(now) now -- ;
if(s[i] == ')') cnt[1] -- ;
}
cout << endl;
}
}
int main()
{
// freopen("galactic.in", "r", stdin);
ios::sync_with_stdio(false), cin.tie(nullptr);
int T = 1;
cin >> T;
while(T -- )
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 3544kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
())(()( ()())())) )()()()( ())()(( ((())())) )(())())) )()))()))) )))))( impossible ()((()( (()())()) ())(()))( (())(()))) ))))(( ()))(( ()((())( ()))()))( ()((())( ()()))( ()))(())) (()(()))) ())((( ())()(( (()(()))) impossible ))))()))) impossible impossible impossible ())(()))( ))()(( (())()()) i...
result:
wrong answer the result string is incorrect (test case 1)