QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582490 | #5108. Prehistoric Programs | deepthought | WA | 5ms | 6944kb | C++23 | 1.2kb | 2024-09-22 16:38:48 | 2024-09-22 16:38:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
pair<int, int> look(const string& s) {
int fin = 0;
int minima = 0;
for(int i = 0; i < s.length(); i++) {
if(s[i] == '(') fin++;
else fin--;
minima = min(fin, minima);
}
return {fin, minima};
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <string> a(n + 1);
vector <pair <int, int>> v1;
vector <pair <int, int>> v2;
for(int i = 1; i <= n; i++) {
cin >> a[i];
auto ax = look(a[i]);
int minima = ax.second;
if(ax.first > 0) {
v1.push_back({minima, i});
}
else {
v2.push_back({- minima, i});
}
}
vector <int> ans;
string s = "";
for(auto x: v1) {
int idx = x.second;
s += a[idx];
ans.push_back(idx);
}
for(auto x: v2) {
int idx = x.second;
s += a[idx];
ans.push_back(idx);
}
auto bx = look(s);
if(bx.second >= 0 && bx.first == 0) {
for(auto x: ans)
cout << x << '\n';
}
else cout << "impossible" << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 6944kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
1 2 5 7 8 9 10 11 12 14 16 17 19 23 27 28 30 32 34 35 37 38 42 43 44 54 55 58 59 61 63 70 72 76 77 79 80 87 91 92 93 94 95 96 97 99 100 106 107 108 109 112 116 117 118 120 122 125 126 127 128 130 131 135 136 143 146 147 148 149 150 151 154 158 161 162 165 166 169 171 174 175 176 177 179 181 182 183 ...
result:
ok good plan
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3868kb
input:
1000 ( ))(())) ((((())())))((())(()))( )( ) ))) ))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()()) )((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))( )))((( ( )))()()()))) ( (((())(((...
output:
impossible
result:
wrong answer you didn't find a solution but jury did