結果

問題 No.154 市バス
ユーザー Pump0129Pump0129
提出日時 2018-09-19 17:23:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 9,392 KB
最終ジャッジ日時 2023-09-25 10:13:13
合計ジャッジ時間 1,943 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
9,344 KB
testcase_01 AC 137 ms
9,392 KB
testcase_02 AC 137 ms
9,268 KB
testcase_03 AC 47 ms
9,364 KB
testcase_04 AC 131 ms
9,312 KB
testcase_05 AC 16 ms
7,788 KB
testcase_06 AC 16 ms
7,820 KB
testcase_07 AC 112 ms
9,264 KB
testcase_08 AC 16 ms
7,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0