結果
問題 | No.154 市バス |
ユーザー | atkrym |
提出日時 | 2016-10-24 00:51:56 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,208 bytes |
コンパイル時間 | 3,512 ms |
コンパイル使用メモリ | 78,364 KB |
実行使用メモリ | 62,092 KB |
最終ジャッジ日時 | 2024-04-21 09:59:33 |
合計ジャッジ時間 | 7,381 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 465 ms
61,940 KB |
testcase_01 | AC | 494 ms
62,092 KB |
testcase_02 | AC | 489 ms
61,800 KB |
testcase_03 | AC | 478 ms
59,664 KB |
testcase_04 | WA | - |
testcase_05 | AC | 134 ms
53,872 KB |
testcase_06 | AC | 134 ms
53,796 KB |
testcase_07 | AC | 492 ms
59,800 KB |
testcase_08 | AC | 137 ms
54,332 KB |
ソースコード
import java.util.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { int n = sc.nextInt(); for (int i = 0;i < n;i++) { if (solve(sc.next())) { System.out.println("possible"); } else { System.out.println("impossible"); } } } private static boolean solve(String s) { int w = 0; List<Integer> g = new ArrayList<>(); List<Integer> r = new ArrayList<>(); for (int i = s.length()-1;i >= 0;i--) { char c = s.charAt(i); if (c == 'W') { if (g.isEmpty() || r.isEmpty()) { return false; } else { w++; } } if (c == 'G') g.add(i); if (c == 'R') r.add(i); } if (g.size() != r.size()) return false; if (w < g.size()) return false; for (int i = 0;i < g.size();i++) { if (r.get(i) < g.get(i)) { return false; } } return true; } }