結果

問題 No.154 市バス
ユーザー yukirinyukirin
提出日時 2016-03-01 23:45:23
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 15,049 ms
コンパイル使用メモリ 243,152 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-21 09:12:52
合計ジャッジ時間 17,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	t := nextInt()
	r := regexp.MustCompile(`R.*?G.*?W`)
	r2 := regexp.MustCompile(`[^D]+`)

	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] = 'D'

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

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

			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 {
			fmt.Println("impossible")
			continue
		}

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

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

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