QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225913 | #5108. Prehistoric Programs | b05704085 | WA | 472ms | 16168kb | Python3 | 1.7kb | 2023-10-25 11:43:30 | 2023-10-25 11:43:30 |
Judging History
answer
#!/usr/bin/env python
# coding: utf-8
# James Teo T12902120
def arrange_tablets(tablets):
count = [] # store count of each tablet
result = [] # result of arrangement of the tablets
# i is the tablet number, tablet is the current tablet
for i, tablet in enumerate(tablets):
open_count = tablet.count('(') # for each "(" count plus 1
close_count = tablet.count(')') # for each ")" count minus 1
total_count = open_count - close_count # sum of the count of the tablet
# if the sum of count is positive place the tablet in the front of the arrangement
if total_count >= 0:
# check if the tablet starts with '(' beacuse the first tablet needs to start with '('
if tablet[0] == '(':
count.insert(0,total_count)
result.insert(0,i+1)
# if tablet count is positive but starts with ")" place it at the 2nd place
else:
count.insert(1,total_count)
result.insert(1,i+1)
# if tablet count is negative put it at the back
else:
count.append(total_count)
result.append(i+1)
# if the total sum of count for all tablet is 0, there is a solution
if sum(count) == 0:
return " ".join(map(str, result))
# if not impossible
else:
return ("impossible")
# Input type 1
n = int(input())
tablets = [input().strip() for _ in range(n)]
# Input type 2
#tablet_input = input()
#tablets = [line for line in tablet_input.split(" ") if line.strip()]
# Call the function to arrange the tablets and check for proper nesting.
print (arrange_tablets(tablets))
#print (tablets)
詳細信息
Test #1:
score: 100
Accepted
time: 472ms
memory: 16168kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
50000 49997 49991 49996 49994 49990 49989 49986 49981 49983 49979 49977 49973 49975 49971 49970 49968 49967 49964 49965 49963 49962 49961 49957 49959 49956 49953 49951 49949 49946 49945 49944 49942 49941 49938 49935 49937 49936 49932 49934 49933 49924 49928 49923 49920 49922 49919 49917 49916 49915 ...
result:
ok good plan
Test #2:
score: 0
Accepted
time: 9ms
memory: 8376kb
input:
1000 ( ))(())) ((((())())))((())(()))( )( ) ))) ))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()()) )((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))( )))((( ( )))()()()))) ( (((())(((...
output:
999 995 996 992 994 989 991 988 984 987 983 981 977 980 975 966 973 967 963 965 962 956 958 954 948 953 952 947 945 946 943 935 941 939 934 933 930 929 927 925 919 915 918 917 913 911 907 910 909 896 904 894 895 892 881 883 879 877 876 872 869 871 865 863 859 857 855 854 852 849 850 846 848 845 842 ...
result:
ok good plan
Test #3:
score: 0
Accepted
time: 6ms
memory: 7960kb
input:
2 () ()
output:
2 1
result:
ok good plan
Test #4:
score: 0
Accepted
time: 12ms
memory: 8036kb
input:
2 (( ))
output:
1 2
result:
ok good plan
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 8044kb
input:
2 )( ()
output:
2 1
result:
wrong answer wrong plan (expected impossible)