QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116302#5108. Prehistoric ProgramsthanhsWA 10ms5772kbC++201.5kb2023-06-28 14:40:142023-06-28 14:40:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 14:40:18]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:5772kb
  • [2023-06-28 14:40:14]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef stack<ll> sll;
typedef queue<ll> qll;
typedef deque<ll> dll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
 
#define endl '\n'
#define pb push_back
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define BACK(i,a,b) for(int i = a; i >= b; i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define bp __builtin_popcountll
#define gcd __gcd
#define bit(i,n) ((n>>i)&1)
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
 
const int MAXN = (1e6)+5;
// const ll SQRT = 4;
const long long inf = 1e18;
const long long MOD = 998244353;

int n,c1,c2,mn[MAXN],cost[MAXN];
pair<pair<int,int>,int> a[MAXN];
string s;

signed main()
{
	fastIO
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	cin>>n;
	FOR(i,0,n-1) a[i].se=i;
	FOR(i,0,n-1) a[i].fi.fi=1e8;
	FOR(i,0,n-1)
	{
		cin>>s;
		FOR(j,0,s.size()-1)
		{
			if(s[j]=='(') c1++;
			else c2++;
			a[i].fi.se+=(s[j]=='('?1:-1);
			a[i].fi.fi=min(a[i].fi.fi,a[i].fi.se);
		}
	}
	if(c1!=c2) {cout<<"impossible"; return 0;}
	sort(a,a+n,greater<pair<pair<int,int>,int>>());
	int cur=0;
	FOR(i,0,n-1)
	{
		if(cur+a[i].fi.fi<0) {cout<<"impossible"; return 0;}
		else cur+=a[i].fi.se;
	}
	FOR(i,0,n-1) cout<<a[i].se+1<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 5772kb

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:

impossible

result:

wrong answer you didn't find a solution but jury did