結果

問題 No.154 市バス
ユーザー tentententen
提出日時 2020-12-04 16:48:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,032 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 72,320 KB
実行使用メモリ 60,684 KB
最終ジャッジ日時 2023-10-13 06:01:51
合計ジャッジ時間 6,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
59,804 KB
testcase_01 AC 362 ms
60,492 KB
testcase_02 AC 361 ms
59,880 KB
testcase_03 AC 375 ms
60,684 KB
testcase_04 AC 374 ms
60,460 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 330 ms
60,456 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char[] arr = new StringBuilder(sc.next()).reverse().toString().toCharArray();
            int r = 0;
            int g = 0;
            int w = 0;
            for (char c : arr) {
                if (c == 'R') {
                    r++;
                } else if (c == 'G') {
                    if (r == 0) {
                        r = -1;
                        break;
                    }
                    r--;
                    g++;
                } else {
                    w = Math.min(w + 1, g);
                }
            }
            if (r == 0 && g == w) {
                sb.append("possible");
            } else {
                sb.append("impossible");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}
0