QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574866 | #5108. Prehistoric Programs | deepthought | WA | 14ms | 9340kb | C++23 | 1.4kb | 2024-09-19 03:50:12 | 2024-09-19 03:50:13 |
Judging History
answer
// for icpc astana quest
#include <bits/stdc++.h>
using namespace std;
const int MAXX = 10005;
struct node{
int glob;
int fin;
string st;
int idx;
bool operator<(const node& other) const {
if (glob != other.glob) return glob > other.glob;
if (fin != other.fin) return fin > other.fin;
return true;
}
};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
set <node> s;
for(int i = 0; i < t; i++) {
string str;
cin >> str;
int res = 0;
int bam = 0;
for(int j = 0; j < str.length(); j++) {
if(str[j] == '(') {
res++;
}
else res--;
bam = min(bam, res);
}
s.insert({bam, res, str, i});
// cout << bam << " " << i << endl;
}
string ans = "";
for(auto x: s) {
ans += x.st;
}
bool ok = true;
int pes = 0;
for(int i = 0; i < ans.length(); i++) {
if(ans[i] == '(') pes++;
else pes--;
if(pes < 0) ok = false;
// cout << i << " " << pes << endl;
}
// cout << ans << endl;
if(pes != 0) cout << "impossible" << '\n';
else if(ok == false) cout << "impossible" << '\n';
else {
for(auto x: s) {
cout << x.idx + 1 << '\n';
}
}
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 9340kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did