結果

問題 No.154 市バス
ユーザー Mcpu3Mcpu3
提出日時 2018-12-05 21:22:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 72,288 KB
実行使用メモリ 60,584 KB
最終ジャッジ日時 2023-09-27 12:23:10
合計ジャッジ時間 6,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 362 ms
60,584 KB
testcase_01 AC 356 ms
59,256 KB
testcase_02 AC 345 ms
60,044 KB
testcase_03 AC 359 ms
60,120 KB
testcase_04 AC 353 ms
58,972 KB
testcase_05 AC 107 ms
55,616 KB
testcase_06 AC 107 ms
55,612 KB
testcase_07 AC 354 ms
59,324 KB
testcase_08 AC 109 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean tmp2;
		int T = sc.nextInt(), tmp1, tmp3, j;
		String S;
		for (int i = 0; i < T; ++i) {
			S = sc.next();
			tmp1 = 0;
			tmp2 = false;
			tmp3 = 0;
			for (j = 0; j < S.length(); ++j) {
				if (S.charAt(j) == 'W') {
					++tmp1;
					tmp2 = true;
				}
				else if (S.charAt(j) == 'G') {
					if (tmp1 == 0) break;
					--tmp1;
					tmp2 = false;
					++tmp3;
				}
				else {
					if (tmp3 == 0) break;
					--tmp3;
				}
			}
			if (j != S.length() || tmp2 || tmp3 != 0) System.out.println("impossible");
			else System.out.println("possible");
		}
		sc.close();
	}
}
0