QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#70684#5108. Prehistoric ProgramsnvmdavaWA 9ms4080kbC++201.3kb2023-01-07 14:33:372023-01-07 14:34:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-07 14:34:50]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:4080kb
  • [2023-01-07 14:33:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second

vector<pair<pair<pair<int, int>, int>, int> > all;
string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;

    for(int i = 1; i <= n; ++i) {
        cin>>s;
        int mn = 0;
        int end = 0;
        int mx = 0;
        for(char c : s) {
            if(c == '(') ++end;
            else --end;
            mn = min(mn, end);
            mx = max(mx, end);
        }
        all.push_back({{{-mn, mx - end}, end}, i});
    }

    sort(all.begin(), all.end(), [](const pair<pair<pair<int, int>, int>, int>& lhs, const pair<pair<pair<int, int>, int>, int>& rhs) {
        if(lhs.ff.ss > 0) {
            if(rhs.ff.ss <= 0) return true;
            return lhs.ff.ff.ff < rhs.ff.ff.ff;
        } else {
            if(rhs.ff.ss > 0) return false;
            return lhs.ff.ff.ss > rhs.ff.ff.ss;
        }
    });

    int cur = 0;
    for(auto& x : all){
        if(cur < x.ff.ff.ff) {
            cout<<"impossible\n";
            return 0;
        }
        cur += x.ff.ss;
    }
    if(cur != 0) {
        cout<<"impossible\n";
        return 0;
    }
    for(auto& x : all){
        cout<<x.ss<<'\n';
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 9ms
memory: 4080kb

input:

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

output:

impossible

result:

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