結果
問題 |
No.154 市バス
|
ユーザー |
![]() |
提出日時 | 2019-12-24 18:45:55 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 213 ms / 2,000 ms |
コード長 | 1,178 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-09-22 08:12:09 |
合計ジャッジ時間 | 2,129 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
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()