QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215000 | #5108. Prehistoric Programs | dereto | WA | 9ms | 3888kb | C++14 | 1.3kb | 2023-10-15 02:04:24 | 2023-10-15 02:04:24 |
Judging History
answer
#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
bool cmp(const tuple<int, int, int> &a, const tuple<int, int, int> &b) {
int s1 = (get<0>(a) == get<1>(a) ? 0 : (get<0>(a) > get<1>(a) ? 1 : -1));
int s2 = (get<0>(b) == get<1>(b) ? 0 : (get<0>(b) > get<1>(b) ? 1 : -1));
if (s1 != s2) return s1 > s2;
if (s1 == 1) return get<1>(a) < get<1>(b);
else return get<0>(a) > get<0>(b);
}
int main(){
int n;
cin >> n;
string str;
vector<tuple<int, int, int>> arr(n, tuple<int, int, int>(0, 0, 0));
for(int i=0;i<n;i++){
cin >> str;
get<2>(arr[i]) = i + 1;
for(int j=0;j<str.length();j++){
if(str[j]=='('){
get<1>(arr[i]) += 1;
}else{
get<1>(arr[i]) -= 1;
}
get<0>(arr[i]) = std::min(get<0>(arr[i]), get<1>(arr[i]));
}
get<1>(arr[i]) -= get<0>(arr[i]);
}
sort(arr.begin(), arr.end(), cmp);
/*
for(int i=0;i<n;i++){
cout << get<0>(arr[i])<<"/"<< get<1>(arr[i])<<"/"<< get<2>(arr[i]) << '\n';
}
*/
int sum = 0;
int min = 0;
for(int i=0;i<n;i++){
min = std::min(min, sum + get<0>(arr[i]));
sum += get<1>(arr[i]) + get<0>(arr[i]);
}
if(sum != 0 || min < 0) {
cout << "impossible";
return 0;
}
for(int i=0;i<n;i++){
cout << get<2>(arr[i]) << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 3888kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did