QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#308147#6568. Space AlignmentMizara#AC ✓9ms9620kbPython3651b2024-01-19 16:46:072024-01-19 16:46:08

Judging History

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

  • [2024-01-19 16:46:08]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:9620kb
  • [2024-01-19 16:46:07]
  • 提交

answer


def f():
	n = int(input())
	res = -1
	q = []
	for i in range(n):
		line = input()
		a, b = 0, 0
		for x in line[:-1]:
			if x == 's':
				a += 1
			else:
				b += 1
		if line[-1] == '{':
			q.append((a, b))
			continue
		x, y = q.pop()
		if x < a:
			x, a = a, x
			y, b = b, y
		if y > b:
			print(-1)
			return
		a = x - a
		b = b - y
		if a == 0 and b == 0:
			continue
		if b == 0:
			print(-1)
			return
		if a % b:
			print(-1)
			return
		a //= b
		if res > 0 and res != a:
			print(-1)
			return
		if a == 0:
			print(-1)
			return
		res = a
	print(max(res, 1))


if __name__ == '__main__':
	f()

详细

Test #1:

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

input:

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 9ms
memory: 9524kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 6ms
memory: 9508kb

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 9ms
memory: 9452kb

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 4ms
memory: 9568kb

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 9ms
memory: 9508kb

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 6ms
memory: 9488kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 9ms
memory: 9432kb

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 9ms
memory: 9452kb

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

score: 0
Accepted
time: 5ms
memory: 9512kb

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 6ms
memory: 9504kb

input:

100
{
}
{
}
{
t{
ssssssssssssssssssssssssssssssssssss}
t{
t}
t{
tssssssssssssssssssssssssssssssssssss{
tssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss{
tsssssssssssssssssssssssssssssssssssst}
ttssssssssssssssssssssssssssssssssssss{
ssssssssssssssssssssssssssssssssssssssssss...

output:

36

result:

ok single line: '36'

Test #12:

score: 0
Accepted
time: 3ms
memory: 9548kb

input:

100
{
t{
tssssssssssssssssssss{
ttssssssssssssssssssss{
tsssssssssssssssssssstt{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{
ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...

output:

20

result:

ok single line: '20'

Test #13:

score: 0
Accepted
time: 5ms
memory: 9456kb

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'