Submission #1479460


Source Code Expand

def menagerie():
	# The key idea is that, if we konw the first two animals
	# by input, we could derive all the others
	n = int(raw_input())
	ans = str(raw_input())

	def _check(f, s, ans):
		siz = len(ans)
		re = ['#']*siz
		re[0] = f
		re[1] = s
		for i in range(1, siz-1):
			_temp_ans = ans[i]
			if re[i]==1:
				if _temp_ans=='o':
					re[i+1] = re[i-1]
				else:
					re[i + 1] = re[i - 1]*(-1)
			if re[i]==-1:
				if _temp_ans=='o':
					re[i+1] = re[i-1]*(-1)
				else:
					re[i + 1] = re[i - 1]
		# check ans[0] and ans[-1]
		c1 = False
		c2 = False
		if re[1]*re[-1]==1:
			if re[0]==1 and ans[0]=='o':
				c1 = True
			if re[0]==-1 and ans[0]=='x':
				c1 = True
		else:
			if re[0]==1 and ans[0]=='x':
				c1 = True
			if re[0]==-1 and ans[0]=='o':
				c1 = True

		if re[-2]*re[0]==1:
			if re[-1]==1 and ans[-1]=='o':
				c2 = True
			if re[-1]==-1 and ans[-1]=='x':
				c2 = True
		else:
			if re[-1]==1 and ans[-1]=='x':
				c2 = True
			if re[-1]==-1 and ans[-1]=='o':
				c2 = True
		if c1 and c2:
			return re
		else:
			return -1
	# w:-1; s:1
	re1 = _check(-1, -1, ans)
	re2 = _check(-1, 1, ans)
	re3 = _check(1, 1, ans)
	re4 = _check(1, -1, ans)

	if re1 != -1:
		op = ['s' if x==1 else 'w' for x in re1]
		print ''.join(op)
		return
	if re2 != -1:
		op = ['s' if x==1 else 'w' for x in re2]
		print ''.join(op)
		return
	if re3 != -1:
		op = ['s' if x==1 else 'w' for x in re3]
		print ''.join(op)
		return
	if re4 != -1:
		op = ['s' if x==1 else 'w' for x in re4]
		print ''.join(op)
		return
	print -1

if __name__ == "__main__":
	menagerie()

Submission Info

Submission Time
Task D - Menagerie
User zhuang
Language Python (2.7.6)
Score 0
Code Size 1645 Byte
Status WA
Exec Time 111 ms
Memory 7652 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 2
AC × 3
WA × 13
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt
Case Name Status Exec Time Memory
00_example_01.txt WA 12 ms 2824 KB
00_example_02.txt AC 11 ms 2824 KB
00_example_03.txt WA 11 ms 2824 KB
01.txt WA 74 ms 5816 KB
02.txt WA 57 ms 5788 KB
03.txt AC 13 ms 2824 KB
04.txt WA 11 ms 2824 KB
05.txt WA 101 ms 7164 KB
06.txt WA 101 ms 7052 KB
07.txt WA 26 ms 3460 KB
08.txt WA 28 ms 3460 KB
09.txt WA 15 ms 2948 KB
10.txt AC 29 ms 3588 KB
11.txt WA 111 ms 7640 KB
12.txt WA 110 ms 7640 KB
13.txt WA 109 ms 7652 KB