結果

問題 No.154 市バス
ユーザー yukirinyukirin
提出日時 2016-03-02 02:20:45
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,053 bytes
コンパイル時間 14,160 ms
コンパイル使用メモリ 240,772 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:17:18
合計ジャッジ時間 15,022 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	t := nextInt()
	ans := make([]byte, 0, 10000)
	imp, po := "impossible\n", "possible\n"

	for i := 0; i < t; i++ {
		s := nextLine()
		flag, min := true, 0
		count := make([]int, 3)
		for i := len(s) - 1; i >= 0; i-- {
			switch s[i] {
			case 'W':
				count[0]++
				if min != 0 {
					min--
				}
			case 'G':
				count[1]++
				min++
			case 'R':
				count[2]++
			}

			if count[2] == 0 && count[0] == 1 {
				flag = false
			}
			if count[2] == 0 && count[1] == 1 {
				flag = false
			}
			if count[1] == 0 && count[0] == 1 {
				flag = false
			}
			if count[1] > count[2] {
				flag = false
			}

			if !flag {
				break
			}
		}

		if !flag || min != 0 || count[2] != count[1] {
			ans = append(ans, imp...)
			continue
		}
		ans = append(ans, po...)
	}
	fmt.Println(string(ans))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
0