QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217639 | #5108. Prehistoric Programs | ucup-team1004# | WA | 7ms | 4328kb | C++14 | 1.2kb | 2023-10-17 07:16:18 | 2023-10-17 07:16:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e6+10,M=1e7+10;
int n;
struct zj{
int x,y,id;
}a[N];
char str[M];
bool operator < (const zj &a,const zj &b){
int p=a.x<a.y,q=b.x<b.y;
if(p^q)return p;
if(p)return a.x<b.x;
else return a.y>b.y;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%s",str+1);
int len=strlen(str+1);
for(int j=1,now=0;j<=len;j++){
if(str[j]=='(')now++;
else now--;
a[i].x=max(a[i].x,-now);
a[i].y=max(a[i].y,now+a[i].x);
}
a[i].id=i;
// debug(a[i].x,a[i].y);
}
sort(a+1,a+1+n);
int now=0;
for(int i=1;i<=n;i++){
if(now<a[i].x)puts("impossible"),exit(0);
now+=a[i].y-a[i].x;
}
if(now)puts("impossible"),exit(0);
for(int i=1;i<=n;i++)printf("%d\n",a[i].id);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 4328kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did