結果

問題 No.154 市バス
ユーザー daleksprinter
提出日時 2018-08-19 17:29:53
言語 Python2
(2.7.18)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 6,784 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-11-17 15:59:55
合計ジャッジ時間 3,853 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

for i in range(n):

	syscnt = 0
	stk = []

	s = raw_input()

	possible = True
	chkind = 0
	wcount = 0
	for j in range(len(s)):
		
		if s[j] == 'W':
			wcount += 1

		if s[j] == 'G':
			stk.append('g')
			syscnt += 1
			if wcount < syscnt:
				possible = False 
			chkind = j
			
		elif s[j] == 'R':
			if not stk :
				possible = False
			else :
				stk.pop()
			
	if stk :
		possible = False

	for i in range(chkind,len(s)):
		if s[i] == 'W':
			possible = False

	print 'possible' if possible else 'impossible'

0