QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#63934 | #5108. Prehistoric Programs | Noobie_99 | WA | 11ms | 6064kb | C++20 | 1.4kb | 2022-11-23 18:36:59 | 2022-11-23 18:37:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[" << __LINE__ << ' ' << #x << "]: " << (x) << endl
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<tuple<int, int, string, int>> a, b;
for (int i=0; i<n; i++) {
string s;
cin >> s;
int cur = 0, mn = 0, mx = 0;
for (char c : s) {
if (c == '(') cur++;
else cur--;
mn = min(mn, cur);
mx = max(mx, cur);
}
if (cur >= 0) a.emplace_back(mn, cur, s, i);
else b.emplace_back(-mx, -cur, s, i);
}
sort(a.begin(), a.end(), [&](auto& x, auto& y) {
return get<0>(x) > get<0>(y);
});
sort(b.begin(), b.end(), [&](auto& x, auto& y) {
return get<0>(x) < get<0>(y);
});
vector<int> ans;
int cur = 0;
bool flag = true;
for (auto& [x, _, y, z] : a) {
for (char c : y) {
if (c == '(') cur++;
else cur--;
if (cur < 0) flag = false;
}
ans.push_back(z);
}
for (auto& [x, _, y, z] : b) {
for (char c : y) {
if (c == '(') cur++;
else cur--;
if (cur < 0) flag = false;
}
ans.push_back(z);
}
if (cur != 0 || !flag) cout << "impossible\n";
else {
for (int e : ans) cout << e+1 << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 6064kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
31744 31767 31765 31764 31763 31759 31757 31755 31754 31753 31750 31747 31768 31743 31740 31738 31736 31734 31727 31726 31722 31721 31711 31710 31796 31818 31817 31815 31814 31812 31809 31806 31803 31801 31799 31798 31705 31795 31794 31793 31789 31787 31785 31784 31782 31777 31775 31634 31658 31656 ...
result:
ok good plan
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3488kb
input:
1000 ( ))(())) ((((())())))((())(()))( )( ) ))) ))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()()) )((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))( )))((( ( )))()()()))) ( (((())(((...
output:
impossible
result:
wrong answer you didn't find a solution but jury did