QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555874#5108. Prehistoric ProgramsevirirRE 0ms0kbC++201.2kb2024-09-10 11:26:182024-09-10 11:26:23

Judging History

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

  • [2024-09-10 11:26:23]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-10 11:26:18]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: