QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#30020#236. Balanced SequencesrfAC ✓60ms4492kbC++14937b2022-04-24 08:46:522022-04-28 12:19:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-28 12:19:19]
  • 评测
  • 测评结果:AC
  • 用时:60ms
  • 内存:4492kb
  • [2022-04-24 08:46:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int T;

int n,ansbase;
struct data{
	int a,b;
	bool operator < (const data w) const{
		if ( a + max(0,w.a - b) != w.a + max(0,a - w.b) ) return a + max(0,w.a - b) < w.a + max(0,a - w.b);
		return a < w.a;
	}
}a[100050];

void work(data &t){
	string s;
	cin >> s;
	t.a = t.b = 0;
	int l = 0;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == '(') ++l;
		else{
			if (l > 0) ansbase += 2,--l;
			else ++t.a;
		}
	}
	t.b = l;
}

void solve(){
	ansbase = 0;
	int suma = 0,sumb = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) work(a[i]),suma += a[i].a,sumb += a[i].b;
	sort(a + 1,a + n + 1);
	int now = 0,premax = 0;
	for (int i = 1; i <= n; ++i){
		now += a[i].a,premax = max(premax,now);
		now -= a[i].b;
	}
	ansbase += 2*(suma-premax);
	cout<<ansbase<<'\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin >> T;
	while (T--) solve();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 60ms
memory: 4492kb

input:

482
2
()())())())()(()))))(())()())))))))))))((()()()))(()()((((((())))(())())
((())(((()(())())())()))))((
2
(()(()))))())))))()(()))(())(
())(()()(()(()))(((()))))))())))))))))(()())()((()))()()))(()(()(((()))
1
))())(())(())(()()()((())())(())))()(()(()(())()((()()()))()((()(()(((()))))(((((()(()...

output:

80
80
88
86
92
90
88
86
92
98
84
96
80
88
96
92
92
90
96
82
92
80
82
84
88
94
88
80
92
82
88
88
88
90
82
88
96
78
96
98
94
98
68
78
82
90
90
92
90
80
78
90
78
84
94
94
84
90
84
92
96
96
82
92
90
90
88
86
94
94
88
94
84
86
96
86
82
90
98
82
78
94
88
86
80
88
96
86
84
86
92
84
84
90
92
82
86
94
84
94
...

result:

ok 482 lines