結果

問題 No.154 市バス
ユーザー yukirin
提出日時 2016-03-02 00:01:20
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 11,408 ms
コンパイル使用メモリ 234,332 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-13 08:07:55
合計ジャッジ時間 15,874 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 5 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"regexp"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	t := nextInt()
	r := regexp.MustCompile(`R[^G]*G[^W]*W`)
	r2 := regexp.MustCompile(`[^W]+`)
	ans := make([]string, 0, 1000)

	for i := 0; i < t; i++ {
		f := true
		b := []byte(nextLine())
		for j := 0; j < len(b)/2; j++ {
			b[j], b[len(b)-1-j] = b[len(b)-1-j], b[j]
		}

		for r.Match(b) {
			b[0] = 'W'

			index := bytes.IndexByte(b, 'G')
			if index == -1 {
				f = true
				break
			}
			b[index] = 'W'

			index2 := bytes.IndexByte(b[index:], 'W')
			if index == -1 {
				f = true
				break
			}
			b[index+index2] = 'W'

			index = bytes.IndexByte(b, 'R')
			f = false

			if index == -1 {
				if r2.Match(b[:index2]) {
					f = true
				}
				break
			}
			if r2.Match(b[:index]) {
				f = true
				break
			}

			b = b[index:]
		}

		if f {
			ans = append(ans, "impossible")
			continue
		}

		if bytes.IndexByte(b, 'G') != -1 || bytes.IndexByte(b, 'R') != -1 {
			ans = append(ans, "impossible")
			continue
		}
		ans = append(ans, "possible")
	}
	fmt.Println(strings.Join(ans, "\n"))
}

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

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