結果

問題 No.154 市バス
ユーザー mkawa2mkawa2
提出日時 2020-01-02 08:49:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-08-14 18:12:46
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
8,604 KB
testcase_01 AC 181 ms
8,584 KB
testcase_02 AC 186 ms
8,588 KB
testcase_03 AC 91 ms
8,712 KB
testcase_04 AC 172 ms
8,664 KB
testcase_05 AC 19 ms
8,716 KB
testcase_06 AC 18 ms
8,648 KB
testcase_07 AC 177 ms
8,720 KB
testcase_08 AC 19 ms
8,792 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