結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2018-09-19 17:23:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,470 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 12,032 KB |
最終ジャッジ日時 | 2024-07-18 08:18:32 |
合計ジャッジ時間 | 1,917 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
class No154: n = 0 que_list = [] def __init__(self): self.n = int(input()) for i in range(self.n): self.que_list.append(input()) def solve(self): ans_list = [] for t in self.que_list: # type: str ans_list.append(self.check_str(t)) return ans_list @staticmethod def check_str(t): if not t.count("G") == t.count("R"): return "impossible" if t.count("G") == 0: return "impossible" if t.count("W") < t.count("G"): return "impossible" g_cnt = 0 r_cnt = 0 w_cnt = 0 is_req_green = False is_req_red = False for c in t: if c == "G": g_cnt += 1 is_req_green = False elif c == "R": r_cnt += 1 is_req_red = False elif c == "W": w_cnt += 1 is_req_green = True is_req_red = True if g_cnt < r_cnt: return "impossible" if w_cnt < r_cnt: return "impossible" if w_cnt < g_cnt: return "impossible" if is_req_red or is_req_green: return "impossible" return "possible" if __name__ == "__main__": que = No154() ans = que.solve() for s in ans: print(s)