結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2015-02-17 23:50:32 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 671 ms / 2,000 ms |
コード長 | 2,864 bytes |
コンパイル時間 | 2,562 ms |
コンパイル使用メモリ | 79,124 KB |
実行使用メモリ | 45,876 KB |
最終ジャッジ日時 | 2024-10-13 06:28:50 |
合計ジャッジ時間 | 6,792 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
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());}}