結果

問題 No.154 市バス
ユーザー mkawa2mkawa2
提出日時 2019-12-24 18:45:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 11,928 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2023-10-22 06:59:15
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 216 ms
10,272 KB
testcase_01 AC 216 ms
10,272 KB
testcase_02 AC 216 ms
10,272 KB
testcase_03 AC 111 ms
10,272 KB
testcase_04 AC 204 ms
10,272 KB
testcase_05 AC 30 ms
10,272 KB
testcase_06 AC 30 ms
10,272 KB
testcase_07 AC 205 ms
10,272 KB
testcase_08 AC 30 ms
10,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def ok(s):
    if s[0]!="W" or s[-1]!="R":return False
    cw = cg = cr = 0
    for c in s:
        if c=="R":
            cr+=1
            if cr>cg:return False
        if c=="G":
            cg+=1
            if cg>cw:return False
        if c=="W":
            cw+=1
    if cr!=cg:return False
    cw = cg = cr = 0
    for c in s[::-1]:
        if c=="R":
            cr+=1
        if c=="G":
            cg+=1
            if cg>cr:return False
        if c=="W":
            cw+=1
            if cg==0:return False
    return True

def main():
    t=II()
    for _ in range(t):
        s=input()
        if ok(s):print("possible")
        else:print("impossible")

main()
0