QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#265862#5108. Prehistoric ProgramsjuampiRE 0ms0kbPython3908b2023-11-25 21:55:522023-11-25 21:55:53

Judging History

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

  • [2023-11-25 21:55:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-25 21:55:52]
  • 提交

answer

while True:
    N = int(input())
    fv, bv = [], []
    tot = 0
    for i in range(N):
        S = input()
        b = 0
        mn = 0
        for j in range(len(S)):
            b += (S[j] == '(') - (S[j] == ')')
            mn = min(mn, b)
        if b >= 0:
            fv.append([-mn, b, i])
        else:
            bv.append([b-mn, -b, i])
        tot += b
    if tot:
        print("impossible")
        continue

    for i in range(2):
        v = fv if i else bv
        v.sort()
        cur = 0
        for j in range(len(v)):
            if cur < v[j][0]:
                print("impossible")
                break
            cur += v[j][1]
        else:
            continue
        break
    else:
        bv.reverse()
        for v in fv:
            print(v[2]+1)
        for v in bv:
            print(v[2]+1)
        continue
    print("impossible")

詳細信息

Test #1:

score: 0
Dangerous Syscalls

input:

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

output:

13
29
65
69
103
129
133
163
164
172
178
241
307
383
418
506
540
542
586
608
652
687
826
896
919
925
929
969
1021
1031
1060
1093
1141
1170
1334
1491
1677
1689
1753
1767
1911
1946
1978
2004
2087
2135
2170
2216
2238
2321
2380
2420
2472
2540
2551
2560
2665
2724
2735
2743
2768
2812
2892
2933
2937
3064
30...

result: