QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#543026#7683. Hard Brackets Problemmhw#WA 15ms3892kbC++231.5kb2024-09-01 12:54:252024-09-01 12:54:26

Judging History

你现在查看的是最新测评结果

  • [2024-09-01 12:54:26]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3892kb
  • [2024-09-01 12:54:25]
  • 提交

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;
			else break;
		}
//		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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

3
((()))
(
)))()

output:

((()))
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 3892kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
()())()))
)()()()()
impossible
impossible
impossible
)()))())))
impossible
impossible
impossible
impossible
())(()))()
(())(())))
impossible
impossible
impossible
()))()))()
impossible
impossible
()))(()))
impossible
())((()))
impossible
impossible
impossible
impossible
impossible
impossi...

result:

wrong answer Jury has the answer but participant has not (test case 5)