結果

問題 No.154 市バス
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-02 22:42:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 977 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 73,796 KB
実行使用メモリ 62,044 KB
最終ジャッジ日時 2023-09-18 18:29:50
合計ジャッジ時間 5,889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 122 ms
55,748 KB
testcase_06 AC 122 ms
55,472 KB
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for(int i = 0; i < t; i++) {
      String s = sc.next();
      int len = s.length();
      int[] w = new int[len];
      int[] g = new int[len];
      int[] r = new int[len];
      int w1 = 0;
      int g1 = 0;
      int p = 0;
      for(int j = 0; j < len; j++) {
        if(s.charAt(j) == 'W') {
          if(j == 0) w[j]++;
          if(j > 0) w[j] = w[j - 1] + 1;
          w1 = j;
        } else if(s.charAt(j) == 'G') {
          if(j == 0) g[j]++;
          if(j > 0) g[j] = g[j - 1] + 1;
          g1 = j;
        } else {
          if(j == 0) r[j]++;
          if(j > 0) r[j] = r[j - 1] + 1;
        }
        if((w[j] < g[j]) || (g[j] < r[j])) p++;
      }
      String ans = "impossible";
      if((p == 0) && (g[len - 1] == r[len - 1]) && (w1 < g1)) ans = "possible";
      System.out.println(ans);
    }
  }
}
0