CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Peli
Sender:rasastusni
Submission time:2020-11-07 22:30:10 +0200
Language:Python2 (PyPy2)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2details
#2ACCEPTED0.04 s2details

Code

#!/usr/bin/env python

seen_states = []
def solve(n, first, second, prev_move, turn):
	#print n, first, second, prev_move, turn
	if (first, second, prev_move, turn) in seen_states:
		return turn
	seen_states.append((first, second, prev_move, turn))
	if first > 0 and prev_move != 2:
		winner = solve(n, first - 1, second, 1, not turn)
		if winner == turn:
			return winner
	if first + 1 != second and prev_move != 1:
		winner = solve(n, first + 1, second, 2, not turn)
		if winner == turn:
			return winner
	if second + 1 < n and prev_move != 3:
		winner = solve(n, first, second + 1, 4, not turn)
		if winner == turn:
			return winner
	if second - 1 != first and prev_move != 4:
		winner = solve(n, first, second - 1, 3, not turn)
		if winner == turn:
			return winner
	return not turn

#for n in range(2, 16):
#	for l in range(n - 1):
#		for r in range(l + 1, n):
#			seen_states = []
#			sol = 2 if solve(n, l, r, None, False) else 1
#			if sol != (r - l) % 2 + 1:
#				print n, l, r, sol
#
#raise Exception('done')

t = int(raw_input())
for x in range(t):
	seen_states = []
	thing = raw_input()
	first = thing.find('P')
	second = first + 1 + thing[first+1:].find('P')
	#print 2 if solve(len(thing), first, second, None, False) else 1
	print (second - first) % 2 + 1

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
PP.
P......P.
.PP
..P.P.
...

correct output
2
2
2
1
2
...

user output
2
2
2
1
2
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
100
.................................

correct output
2
1
2
1
1
...

user output
2
1
2
1
1
...
Truncated