結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 444 ms
59,028 KB
testcase_01 AC 468 ms
58,816 KB
testcase_02 AC 476 ms
59,024 KB
testcase_03 WA -
testcase_04 AC 479 ms
59,116 KB
testcase_05 AC 152 ms
54,020 KB
testcase_06 AC 162 ms
53,976 KB
testcase_07 AC 451 ms
58,684 KB
testcase_08 AC 163 ms
53,712 KB
権限があれば一括ダウンロードができます

ソースコード

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;
			boolean catch_one = false;
			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;
					}
					
					catch_one = true;
				}
				
				while(R_queue.size() >= 2 && G_queue.size() >= 2 && catch_one){
					R_queue.remove();
					G_queue.remove();
					
					while(!G_queue.isEmpty() && G_queue.peek() > R_queue.peek()){
						G_queue.remove();
					}
					catch_one = false;
				}
				
				//System.out.println(i + " " + R_queue + " " + G_queue);
				if(R_queue.size() < G_queue.size()){
					ok = false;
					break;
				}
			}
			
			System.out.println(ok && catch_one ? "possible" : "impossible");
			
		}
		
	}
	
}
0