結果

問題 No.154 市バス
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 10:13:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 2,852 ms
コンパイル使用メモリ 79,240 KB
実行使用メモリ 59,752 KB
最終ジャッジ日時 2024-04-21 08:47:55
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 452 ms
58,756 KB
testcase_01 AC 440 ms
59,152 KB
testcase_02 AC 458 ms
59,068 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 150 ms
53,616 KB
testcase_06 AC 155 ms
53,776 KB
testcase_07 AC 442 ms
58,932 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int T = sc.nextInt();
		for(int tt = 0; tt < T; tt++){
			final char[] input = sc.next().toCharArray();
			
			LinkedList<Integer> R_queue = new LinkedList<Integer>();
			LinkedList<Integer> G_queue = new LinkedList<Integer>();
			
			boolean ok = true;
			for(int i = input.length - 1; i >= 0; i--){
				if(input[i] == 'R'){
					R_queue.add(i);
				}else if(input[i] == 'G'){
					G_queue.add(i);
				}else if(input[i] == 'W'){
					if(R_queue.isEmpty() || G_queue.isEmpty()){
						ok = false;
						break;
					}
				}
				
				while(R_queue.size() >= 2 && G_queue.size() >= 2){
					R_queue.remove();
					G_queue.remove();
					
					while(!G_queue.isEmpty() && G_queue.peek() > R_queue.peek()){
						G_queue.remove();
					}
				}
				
				if(R_queue.size() < G_queue.size()){
					ok = false;
					break;
				}
				
				//System.out.println(i + " " + R_queue + " " + G_queue);
			}
			
			System.out.println(ok ? "possible" : "impossible");
			
		}
		
	}
	
}
0