結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
yoza
|
| 提出日時 | 2016-06-12 13:54:31 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 593 bytes |
| コンパイル時間 | 95 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 13,312 KB |
| 最終ジャッジ日時 | 2024-10-13 08:28:08 |
| 合計ジャッジ時間 | 4,434 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 8 |
コンパイルメッセージ
Syntax OK
ソースコード
def solve(s)
last_w = 0
last_g = 0
counter = {W: 0, G: 0}
s.each_char.with_index do |c, i|
if c == 'W'
last_w = i
counter[:W] += 1
elsif c == 'G'
if counter[:W] == 0
return false
else
last_g = i
counter[:W] -= 1
counter[:G] += 1
end
else
if counter[:G] == 0
return false
else
counter[:G] -= 1
end
end
end
if last_w > last_g or counter[:G] != 0
return false
end
return true
end
n = gets.to_i
n.times do
puts solve(gets.chomp) ? 'possible' : 'impossible'
end
yoza