結果

問題 No.154 市バス
ユーザー GrenacheGrenache
提出日時 2016-02-14 10:13:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 5,069 ms
コンパイル使用メモリ 77,512 KB
実行使用メモリ 58,656 KB
最終ジャッジ日時 2024-04-21 09:08:36
合計ジャッジ時間 7,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 382 ms
46,352 KB
testcase_01 AC 390 ms
46,740 KB
testcase_02 AC 343 ms
46,924 KB
testcase_03 AC 376 ms
48,004 KB
testcase_04 WA -
testcase_05 AC 122 ms
41,504 KB
testcase_06 AC 124 ms
41,216 KB
testcase_07 AC 330 ms
46,664 KB
testcase_08 AC 124 ms
41,344 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;
        	for (int i = n - 1; flag && i >= 0; i--) {
        		char c = s[i];

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

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

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

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

        sc.close();
    }
}
0