結果

問題 No.154 市バス
ユーザー sue_charosue_charo
提出日時 2017-04-17 17:49:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-21 10:15:11
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
12,544 KB
testcase_01 AC 129 ms
12,672 KB
testcase_02 AC 130 ms
12,544 KB
testcase_03 AC 107 ms
12,544 KB
testcase_04 AC 125 ms
12,544 KB
testcase_05 AC 40 ms
11,264 KB
testcase_06 AC 40 ms
11,392 KB
testcase_07 AC 128 ms
12,416 KB
testcase_08 AC 41 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, l_memo):
    ans_list = []
    for memo in l_memo:
        l_bus = list(memo)
        w_count = 0
        g_count = 0
        r_count = 0
        
        all_flag = 0
        w_flag = 1

        for bus in l_bus:
            if bus == "W":
                w_count += 1
                w_flag = 1
            elif bus == "G":
                g_count += 1
                w_flag = 0
            elif bus == "R":
                r_count += 1

            if w_count < g_count or g_count < r_count:
                all_flag = 1
                break
        
        if all_flag == 0 and w_flag == 0 and w_count >= g_count == r_count:
            ans_list.append("possible")
        else:
            ans_list.append("impossible")

    return ans_list

 
def main():
    N = II()
    l_memo = [""] * N
    for i in range(N):
        l_memo[i] = str(input())

    for ans in solve(N, l_memo):
        print(ans)
 
 
if __name__ == "__main__":
    main()
0