結果

問題 No.154 市バス
ユーザー yukirinyukirin
提出日時 2016-03-02 00:47:58
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,050 bytes
コンパイル時間 11,053 ms
コンパイル使用メモリ 218,336 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:15:28
合計ジャッジ時間 11,814 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

	for i := 0; i < t; i++ {
		f := true
		b := []byte(nextLine())

		r := bytes.LastIndexByte(b, 'R')
		for len(b)-1 == r {
			b[r] = 'D'

			g := bytes.LastIndexByte(b, 'G')
			if g == -1 {
				f = true
				break
			}
			b[g] = 'D'

			w := bytes.LastIndexByte(b, 'W')
			if w == -1 || w > g {
				f = true
				break
			}
			b[w] = 'D'

			r = bytes.LastIndexByte(b[:r], 'R')
			f = false
			if r == -1 {
				break
			}
			b = b[:r+1]
		}
		if f {
			ans = append(ans, imp...)
			continue
		}

		if bytes.LastIndexByte(b, 'G') != -1 || bytes.LastIndexByte(b, 'R') != -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