QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#30016 | #237. Triangle Partition | srf | RE | 0ms | 0kb | C++14 | 871b | 2022-04-24 08:38:49 | 2022-04-28 12:19:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T;
int n,ansbase;
struct data{
int a,b;
bool operator < (const data w) const{
return a + max(0,w.a - b) < w.a + max(0,a - w.b);
}
}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,a[i].a);
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;
}
详细
Test #1:
score: 0
Runtime Error
input:
190 10 -7215 2904 -5179 1663 -542 1091 -5687 7868 7838 -1048 -2944 4346 -2780 3959 -9402 1099 -8548 -7238 -3821 -2917 2713 295 -856 -8661 7651 3945 -8216 -543 5798 5024 8583 -3384 -1208 5955 3068 -385 340 2968 6559 -272 4537 5075 5126 4343 639 8281 1700 2572 819 9317 -9854 -1316 -3421 -1137 9368 718...
output:
78