結果

問題 No.154 市バス
ユーザー threepipes_sthreepipes_s
提出日時 2015-02-17 23:33:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,709 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 78,392 KB
実行使用メモリ 42,304 KB
最終ジャッジ日時 2024-04-21 07:35:21
合計ジャッジ時間 4,268 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
public class Main {
	public static boolean result[];
	public static int dp[][];
	public static void main(String[] args) throws NumberFormatException, IOException{
		ContestScanner in = new ContestScanner();
		int t = in.nextInt();
		for(int i=0; i<t; i++){
			String s = in.nextToken();
			boolean pos = true;
			int[] bus = new int[3];
			for(int j=0; j<s.length(); j++){
				char c = s.charAt(j);
				if(c == 'W'){
					for(int k=0; k<3; k++){
						if(bus[k] == 0){
							bus[k]++;
							break;
						}
					}
				}else if(c == 'G'){
					boolean check = false;
					for(int k=0; k<3; k++){
						if(bus[k] == 1){
							bus[k]++;
							check = true;
							break;
						}
					}
					if(!check) pos = false;
				}else if(c == 'R'){
					boolean check = false;
					for(int k=0; k<3; k++){
						if(bus[k] == 2){
							bus[k]++;
							check = true;
							break;
						}
					}
					if(!check) pos = false;
				}
				if(!pos) break;
			}
			for(int j=0; j<3; j++){
				if(bus[j] != 0 && bus[j] != 1 && bus[j] != 3) pos = false;
			}
			
			if(pos) System.out.println("possible");
			else System.out.println("impossible");
		}
	}
}

class MyComp implements Comparator<int[]>{
	public int compare(int[] a, int[] b) {
		return a[0] - b[0];
	}
}

class Reverse implements Comparator<Integer>{
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class Node{
	int id;
	List<Node> edge = new ArrayList<Node>();
	public Node(int id){
		this.id = id;
	}
	public void createEdge(Node node){
		edge.add(node);
	}
}

class ContestScanner{
	private BufferedReader reader;
	private String[] line;
	private int idx;
	public ContestScanner() throws FileNotFoundException{
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException{
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
	}
	
	public String nextToken() throws IOException{
		if(line == null || line.length <= idx){
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}
	public long nextLong() throws IOException, NumberFormatException{
		return Long.parseLong(nextToken());
	}
	public int nextInt() throws NumberFormatException, IOException{
		return (int)nextLong();
	}
	public double nextDouble() throws NumberFormatException, IOException{
		return Double.parseDouble(nextToken());
	}
}
0