結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
tnoda_
|
| 提出日時 | 2015-02-18 17:09:20 |
| 言語 | Go (1.25.7) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 1,230 bytes |
| 記録 | |
| コンパイル時間 | 12,190 ms |
| コンパイル使用メモリ | 238,112 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-01 17:25:39 |
| 合計ジャッジ時間 | 13,364 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
func next() string {
// sc.Split(bufio.ScanWords) // 削除: Scan後に呼ぶとPanicになるため
if !sc.Scan() {
panic("could not scan a word from the reader")
}
return sc.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return i
}
func nextLong() int64 {
i, e := strconv.ParseInt(next(), 10, 64)
if e != nil {
panic(e)
}
return i
}
func nextLine() string {
// sc.Split(bufio.ScanLines) // 削除: 同上
if !sc.Scan() {
panic("could not scan a line from the reader")
}
return sc.Text()
}
func solve() (res string) {
res = "impossible"
sr := strings.NewReader(next())
var W0, W1, G, R int
for {
b, e := sr.ReadByte()
if e != nil {
break
}
switch b {
case byte('W'):
W0++
W1++
case byte('G'):
W0 = 0
G++
case byte('R'):
R++
}
if R > G || G > W1 {
return
}
}
if W0 == 0 && G == R {
res = "possible"
}
return
}
func main() {
// Scan開始前にSplitを設定しないとPanicになるため、ここに移動
sc.Split(bufio.ScanWords)
N := nextInt()
for i := 0; i < N; i++ {
fmt.Println(solve())
}
}
tnoda_