結果

問題 No.154 市バス
ユーザー GrenacheGrenache
提出日時 2016-02-14 10:26:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 3,597 ms
コンパイル使用メモリ 73,972 KB
実行使用メモリ 61,024 KB
最終ジャッジ日時 2023-08-03 11:16:51
合計ジャッジ時間 7,095 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 357 ms
60,684 KB
testcase_01 AC 400 ms
60,328 KB
testcase_02 AC 399 ms
60,572 KB
testcase_03 AC 388 ms
59,992 KB
testcase_04 AC 396 ms
61,024 KB
testcase_05 AC 126 ms
55,796 KB
testcase_06 AC 126 ms
55,940 KB
testcase_07 AC 395 ms
60,840 KB
testcase_08 AC 123 ms
55,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder154 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        for (int tcase = 0; tcase < t; tcase++) {
        	char[] s = sc.next().toCharArray();
        	int n = s.length;

        	boolean flag = true;
        	int r = 0;
        	int g = 0;
        	int w = 0;
//        	int dr = 0;
//        	int dg = 0;
//        	int dw = 0;
        	for (int i = n - 1; flag && i >= 0; i--) {
        		char c = s[i];

        		if (c == 'R') {
        			r++;
//        			dr++;
        		} else if (c == 'G') {
        			g++;
//        			dg++;
        		} else {
        			w++;
//        			dw++;
        		}

        		if (g > r) {
        			flag = false;
        		}
        		if (w > 0 && g == 0) {
        			flag = false;
        		}
        		if (w > 0 && g > 1) {
        			w = 0;
        			g--;
        			r--;
        		}
        	}

        	if (r != 1 || g != 1 || w == 0) {
        		flag = false;
        	}

//        	System.out.printf("%d %d %d\n", dr, dg, dw);

        	if (flag) {
        		System.out.println("possible");
        	} else {
        		System.out.println("impossible");
        	}
        }

        sc.close();
    }
}
0