結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
threepipes_s
|
| 提出日時 | 2015-02-17 23:33:24 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,709 bytes |
| コンパイル時間 | 2,590 ms |
| コンパイル使用メモリ | 78,552 KB |
| 実行使用メモリ | 42,104 KB |
| 最終ジャッジ日時 | 2024-10-13 06:20:38 |
| 合計ジャッジ時間 | 4,301 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 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[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());
}
}
threepipes_s