QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353505#5108. Prehistoric ProgramsJerryTclWA 9ms4060kbC++20837b2024-03-14 10:13:522024-03-14 10:13:54

Judging History

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

  • [2024-03-14 10:13:54]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:4060kb
  • [2024-03-14 10:13:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, x = 0; cin >> n; string brk;
    vector<pair<int, int>> lst(n);
    for(int i = 0; i < n; ++i) {
        auto &[x, y] = lst[i]; cin >> brk;
        for(const char c : brk)
            y = min(y, x += c == '(' ? 1 : -1);
    }
    vector<int> d(n); iota(d.begin(), d.end(), 0);
    sort(d.begin(), d.end(), [&](int u, int v) {
        const auto [ux, uy] = lst[u]; const int su = ux >= 0;
        const auto [vx, vy] = lst[v]; const int sv = vx >= 0;
        return su == sv ? su ? uy > vy : uy - ux < vy - vx : su > sv;
    });
    for(int i = 0; i < n; x += lst[d[i++]].first)
        if(x + lst[d[i]].second < 0) return puts("-1"), 0;
    if(x) puts("impossible"); else for(int i : d) printf("%d\n", i + 1);
}

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 4060kb

input:

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

output:

26700
26740
26738
26737
26729
26727
26724
26723
26716
26715
26714
26713
26711
26709
26703
26744
26698
26696
26695
26693
26692
26689
26685
26682
26679
26677
26674
26672
26671
26670
26779
26819
26817
26815
26813
26810
26809
26806
26803
26802
26800
26792
26787
26784
26783
26668
26778
26777
26776
26773
...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 1ms
memory: 3792kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

827
271
595
268
267
596
265
598
258
257
929
604
590
253
252
826
825
933
934
247
245
243
242
290
919
301
563
564
297
296
566
570
573
291
611
575
576
287
286
577
584
282
280
585
925
947
208
636
206
638
640
814
945
198
197
646
209
190
189
188
948
650
652
653
655
182
181
626
935
239
822
615
617
619
229
...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

2
()
()

output:

1
2

result:

ok good plan

Test #4:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

2
((
))

output:

1
2

result:

ok good plan

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3572kb

input:

2
)(
()

output:

-1

result:

wrong answer wrong plan (expected impossible)