問題一覧 > 通常問題

No.154 City Bus

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 64 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 297
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 372 / 自分の提出
問題文最終更新日: 2026-06-25 01:57:36
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 87 (順位表) の他の問題:

Problem Statement

Kyoto's city buses run on several routes.
For each route, the last bus of the day and the bus $1$ before the last bus have display board lights of a different color than usual.
The usual light color is white, but the light of the bus 1 before the last bus is green, and the light of the last bus is red.
From the first bus to the last bus of the day, yuki checked the light colors of all buses passing along a certain road, and wrote them down in a memo in the order in which they were seen.
yuki is worried that the memo may contain mistakes.
Write a program that checks whether the order of light colors shown in this memo is a possible pattern.
Here, assume that city buses of every route run at least $3$ times every day, and follow the same path throughout $1$ day.


Figure 1. A Kyoto city bus on Route 3, with the usual light. Incidentally, the characters become slightly harder to read with green or red lights (at Hyakumanben, February 4, 2015)

Input

The $1$st line of the input contains an integer $T$, the number of test cases.
Each test case consists of $1$ line, containing a string $S$.
The $i$-th character of the string $S$ indicates the light color of the $i$-th bus seen in yuki's memo for that day, where $\verb|W|$ means white, $\verb|G|$ means green, and $\verb|R|$ means red. No other characters are included.

  • $1 \leq T \leq 1000$
  • $1 \leq |S| \leq 1000$

Output

For each test case, output $\verb|possible|$ if it is a possible pattern, and $\verb|impossible|$ otherwise.

Sample

Sample 1
Input
5
WWWWWWWWWGR
WWWWGWGRR
WWWWWWWWWWWWWWGRRG
WGRWGR
WWWWWWWWWWWWWWWWWGGWGWGGWGWGGGWGG
Output
possible
possible
impossible
possible
impossible

Test case 1: There are buses of only 1 route.
Test case 2: There are buses of 2 routes.
Test case 3: On one of the routes, a bus with a green light seems to run after the last bus, which is somehow strange.
Test case 4: So it can also happen that one route starts running after the last bus of another route has finished.
Test case 5: It is not possible for there to be no last bus.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。