結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
koheijkt
|
| 提出日時 | 2026-02-24 17:59:03 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
AC
|
| 実行時間 | 544 ms / 2,000 ms |
| コード長 | 2,007 bytes |
| 記録 | |
| コンパイル時間 | 745 ms |
| コンパイル使用メモリ | 20,828 KB |
| 実行使用メモリ | 15,576 KB |
| 最終ジャッジ日時 | 2026-02-24 17:59:10 |
| 合計ジャッジ時間 | 6,140 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 1e18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def I(): return input().rstrip()
def II(): return int(input().rstrip())
def IS(): return input().rstrip().split()
def MII(): return map(int, input().rstrip().split())
def LI(): return list(input().rstrip())
def TII(): return tuple(map(int, input().rstrip().split()))
def LII(): return list(map(int, input().rstrip().split()))
def LSI(): return list(map(str, input().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
T = II()
d = {}
d['W'] = 0
d['G'] = 1
d['R'] = 2
for i in range(T):
S = I()
data = [list() for _ in range(3)]
for i, s in enumerate(S):
data[d[s]].append(i)
# 一個はあるはず
# G, R は同じ個数のはず
# W のカウントは G より多いはず
if len(data[0]) == 0 or len(data[1]) == 0 or len(data[2]) == 0 \
or len(data[1]) != len(data[2]) or len(data[0]) < len(data[1]) \
or data[1][-1] < data[0][-1]:
print('impossible')
continue
flag = True
while data[2]:
# R
pos2 = data[2].pop()
# G: 貪欲に一番後ろを取る
pos1 = data[1].pop()
# W: pos1 より右側にあるものは捨てる
while data[0] and data[0][-1] > pos1:
data[0].pop()
if data[0]:
pos0 = data[0].pop()
else:
flag = False
break
# 順番の判定
if not (pos0 < pos1 < pos2):
flag = False
break
# break しなかったら次のペアへ
if flag:
print('possible')
else:
print('impossible')
koheijkt