QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356446#5108. Prehistoric ProgramsTWTP_TCTF#WA 7ms4136kbC++141.6kb2024-03-17 19:48:142024-03-17 19:48:14

Judging History

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

  • [2024-03-17 19:48:14]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:4136kb
  • [2024-03-17 19:48:14]
  • 提交

answer

#include<iostream>
#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e4 + 9, MOD = 998244353;

// + +, - - , - +
//(((  , )))  , )))(((
pair<int, int> calc(string &s) {
    int cnt = 0;
    int mn = 0;
    for (auto i: s) {
        if (i == '(') {
            cnt++;
        } else {
            cnt--;
        }
        mn = min(mn, cnt);
    }
    return {mn, cnt};
}

// )))) , )))(((( -3 , 1      // )(((  ))))))) (((((((((((      // 7,5 // 5,5
bool sortt(pair<int, pair<int, int> > &x, pair<int, pair<int, int> > &y) {
    pair<int, int> a = x.second, b = y.second;
    if (a.second >= 0 && b.second >= 0) {
        return a.first > b.first;
    }
    if (a.second <= 0 && b.second <= 0) {
        return a.first < b.first;
    }
    return a.second > b.second;
}

void doWork() {
    // x , d
    int n;
    cin >> n;
    vector<pair<int, pair<int, int> > > v;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        v.push_back({i, calc(s)});
    }
    sort(v.begin(), v.end(), sortt);
    ll total = 0;
    for (auto i: v) {
        if (total + i.second.first < 0) {
            cout << "impossible";
            return;
        }
        total += i.second.second;
    }
    if (total != 0) {
        cout << "impossible";
    } else {
        for (auto i: v)cout << i.first << "\n";
    }
}

int main() {

    IO
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
        //  cout << "Case #" << i << ": ";
        doWork();
    }
}

詳細信息

Test #1:

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

input:

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

output:

impossible

result:

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