結果

問題 No.154 市バス
ユーザー threepipes_sthreepipes_s
提出日時 2015-02-17 23:42:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,724 bytes
コンパイル時間 2,784 ms
コンパイル使用メモリ 78,520 KB
実行使用メモリ 50,312 KB
最終ジャッジ日時 2024-04-21 07:37:51
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 508 ms
45,468 KB
testcase_01 AC 529 ms
45,396 KB
testcase_02 AC 526 ms
45,304 KB
testcase_03 AC 485 ms
45,204 KB
testcase_04 AC 631 ms
45,252 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 371 ms
45,336 KB
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[1000];
			for(int j=0; j<s.length(); j++){
				char c = s.charAt(j);
				if(c == 'W'){
					for(int k=0; k<1000; k++){
						if(bus[k] == 0){
							bus[k]++;
							break;
						}
					}
				}else if(c == 'G'){
					boolean check = false;
					for(int k=0; k<1000; 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<1000; k++){
						if(bus[k] == 2){
							bus[k]++;
							check = true;
							break;
						}
					}
					if(!check) pos = false;
				}
				if(!pos) break;
			}
			for(int j=0; j<1000; 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