QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583089#5108. Prehistoric ProgramsdeepthoughtWA 7ms7232kbC++231.4kb2024-09-22 18:17:192024-09-22 18:17:21

Judging History

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

  • [2024-09-22 18:17:21]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:7232kb
  • [2024-09-22 18:17:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
pair<int, int> look(const string& s) {
    int fin = 0;
    int minima = 0;
    for(int i = 0; i < s.length(); i++) {
        if(s[i] == '(') fin++;
        else fin--;
        // if(s.length() == 150) cout << i << " " << fin << endl;
        minima = min(fin, minima);
    }
    return {fin, minima};
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <string> a(n + 1);
    vector <pair <int, int>> v1;
    vector <pair <int, int>> v2;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        auto ax = look(a[i]);
        int minima = ax.second;
        int fin = ax.first;
        if(fin >= 0) {
            v1.push_back({-minima, i});
        }
        else {
            v2.push_back({-fin, i});
        }
    }
    vector <int> ans;
    string s = "";
    
    sort(v1.begin(), v1.end());
    for(auto x: v1) {
        int idx = x.second;
        s += a[idx];
        ans.push_back(idx);
    }


    sort(v2.begin(), v2.end());
    for(auto x: v2) {
        int idx = x.second;
        s += a[idx];
        // cout << idx << " " << a[idx] << endl;
        ans.push_back(idx);
    }

    auto bx = look(s);
    
    if(bx.second >= 0 && bx.first == 0) {
        for(auto x: ans)
            cout << x << '\n';
    }
    else cout << "impossible" << '\n';
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 7232kb

input:

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

output:

impossible

result:

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