結果

問題 No.154 市バス
ユーザー yuki2006yuki2006
提出日時 2016-06-21 00:22:14
言語 Go
(1.22.1)
結果
AC  
実行時間 1,007 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 14,388 ms
コンパイル使用メモリ 208,492 KB
実行使用メモリ 8,060 KB
最終ジャッジ日時 2023-08-18 07:51:51
合計ジャッジ時間 22,778 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,007 ms
8,056 KB
testcase_01 AC 1,007 ms
8,056 KB
testcase_02 AC 1,001 ms
8,056 KB
testcase_03 AC 1,006 ms
8,052 KB
testcase_04 AC 1,002 ms
8,060 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 998 ms
8,060 KB
testcase_08 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func check(s string) bool {
	R := 0
	G := 0
	W := 0
	for i := len(s) - 1; i >= 0; i-- {
		switch s[i] {
		case 'R':
			R++
		case 'G':
			if 0 < R {
				R--
				G++
			} else {
				return false
			}
		case 'W':
			if 0 < G {
				G--
			} else if 0 == W {
				return false
			}
			W++
		}
	}
	return R == 0 && G == 0
}
func main() {
	var N int
	fmt.Scanf("%d", &N)
	for i := 0; i < N; i++ {
		var s string
		fmt.Scanf("%s", &s)
		if check(s) {
			fmt.Println("possible")
		} else {
			fmt.Println("impossible")
		}
	}
}
0