QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353503#5108. Prehistoric ProgramsJerryTclWA 10ms4144kbC++20829b2024-03-14 10:13:142024-03-14 10:13:16

Judging History

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

  • [2024-03-14 10:13:16]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:4144kb
  • [2024-03-14 10:13:14]
  • 提交

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("-1"); else for(int i : d) printf("%d\n", i + 1);
}

詳細信息

Test #1:

score: 100
Accepted
time: 10ms
memory: 4072kb

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: 4144kb

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: 1ms
memory: 3984kb

input:

2
()
()

output:

1
2

result:

ok good plan

Test #4:

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

input:

2
((
))

output:

1
2

result:

ok good plan

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3552kb

input:

2
)(
()

output:

-1

result:

wrong answer wrong plan (expected impossible)