QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#265862 | #5108. Prehistoric Programs | juampi | RE | 0ms | 0kb | Python3 | 908b | 2023-11-25 21:55:52 | 2023-11-25 21:55:53 |
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...