結果
問題 | No.154 市バス |
ユーザー | uafr_cs |
提出日時 | 2015-09-02 10:21:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 525 ms / 2,000 ms |
コード長 | 1,361 bytes |
コンパイル時間 | 2,627 ms |
コンパイル使用メモリ | 79,356 KB |
実行使用メモリ | 59,172 KB |
最終ジャッジ日時 | 2024-04-21 08:48:29 |
合計ジャッジ時間 | 7,186 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 477 ms
58,860 KB |
testcase_01 | AC | 442 ms
59,172 KB |
testcase_02 | AC | 473 ms
58,872 KB |
testcase_03 | AC | 525 ms
58,944 KB |
testcase_04 | AC | 473 ms
58,676 KB |
testcase_05 | AC | 166 ms
54,124 KB |
testcase_06 | AC | 163 ms
54,076 KB |
testcase_07 | AC | 473 ms
58,900 KB |
testcase_08 | AC | 160 ms
53,744 KB |
ソースコード
import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int T = sc.nextInt(); for(int tt = 0; tt < T; tt++){ final char[] input = sc.next().toCharArray(); LinkedList<Integer> R_queue = new LinkedList<Integer>(); LinkedList<Integer> G_queue = new LinkedList<Integer>(); boolean ok = true; boolean catch_one = false; for(int i = input.length - 1; i >= 0; i--){ if(input[i] == 'R'){ R_queue.add(i); }else if(input[i] == 'G'){ G_queue.add(i); }else if(input[i] == 'W'){ if(R_queue.isEmpty() || G_queue.isEmpty()){ ok = false; break; } catch_one = true; } while(R_queue.size() >= 2 && G_queue.size() >= 2 && catch_one){ R_queue.remove(); G_queue.remove(); while(!G_queue.isEmpty() && G_queue.peek() > R_queue.peek()){ G_queue.remove(); } catch_one = false; } //System.out.println(i + " " + R_queue + " " + G_queue); if(R_queue.size() < G_queue.size()){ ok = false; break; } } System.out.println(ok && catch_one && (G_queue.size() == 1 && R_queue.size() == 1) ? "possible" : "impossible"); } } }