QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555874 | #5108. Prehistoric Programs | evirir | RE | 0ms | 0kb | C++20 | 1.2kb | 2024-09-10 11:26:18 | 2024-09-10 11:26:23 |
answer
#include <bits/stdc++.h>
using namespace std;
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
using ll = long long;
using ii = pair<ll, ll>;
using ld = long double;
struct St
{
int id;
int net;
int mn;
bool operator<(const St& o) const
{
if ((net >= 0) != (o.net >= 0)) return net >= 0;
if (net >= 0) return mn >= o.mn;
return mn <= o.mn;
}
};
void fail()
{
cout<<"impossible\n";
exit(0);
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n; cin>>n;
vector<St> a(n);
forn(i,0,n)
{
string s; cin>>s;
int sum = 0;
int mn = 0;
for (const auto c : s)
{
if (c == '(') sum++;
else sum--;
mn = min(mn, sum);
}
a[i] = {i, sum, mn};
}
sort(all(a));
int sum = 0;
forn(i,0,n)
{
if (sum + a[i].mn < 0) fail();
sum += a[i].net;
}
if (sum != 0) fail();
forn(i, 0, n) cout << a[i].id + 1 << '\n';
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...