結果

問題 No.154 市バス
ユーザー threepipes_sthreepipes_s
提出日時 2015-02-17 23:50:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 712 ms / 2,000 ms
コード長 2,864 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 78,932 KB
実行使用メモリ 46,024 KB
最終ジャッジ日時 2024-04-21 07:43:57
合計ジャッジ時間 7,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 561 ms
45,596 KB
testcase_01 AC 570 ms
45,660 KB
testcase_02 AC 516 ms
45,732 KB
testcase_03 AC 536 ms
46,024 KB
testcase_04 AC 712 ms
45,984 KB
testcase_05 AC 52 ms
36,988 KB
testcase_06 AC 52 ms
36,692 KB
testcase_07 AC 398 ms
45,660 KB
testcase_08 AC 52 ms
37,368 KB
権限があれば一括ダウンロードができます

ソースコード

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;
			}
			int g = 0;
			for(int j=s.length()-1; j>=0; j--){
				if(s.charAt(j) == 'G') g++;
				if(s.charAt(j) == 'W' && g == 0) 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