結果

問題 No.154 市バス
ユーザー ムチャムチャ
提出日時 2016-06-27 11:49:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,002 bytes
コンパイル時間 4,443 ms
コンパイル使用メモリ 79,080 KB
実行使用メモリ 59,580 KB
最終ジャッジ日時 2024-04-21 09:48:23
合計ジャッジ時間 8,637 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 414 ms
58,408 KB
testcase_01 AC 431 ms
59,268 KB
testcase_02 AC 421 ms
59,464 KB
testcase_03 AC 414 ms
58,320 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 423 ms
58,780 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class TownBus {

	public static void main(String[] args) {
		List<String> input = new ArrayList<>();
		try(Scanner s = new Scanner(System.in)){
			int c = Integer.parseInt(s.nextLine());
			//s.nextLine();
			for(int i = 0; i < c ; i++){
				String line = s.nextLine();
				input.add(line);
			}
		}
		for(String line : input){
			check(line);
		}
	}

	private static void check(String s){
		Deque<Character> green = new ArrayDeque<>();
		for(char light : s.toCharArray()){
			switch(light){
			case 'W':
				break;
			case 'G':
				green.push(light);
				break;
			case 'R':
				if(green.pollFirst() == null){
					System.out.println("impossible");
					return;
				}
				break;
			default:
				System.out.println("impossible");
				return;
			}
		}
		if(green.isEmpty()){
			System.out.println("possible");
		}else{
			System.out.println("impossible");
		}
	}
}
0