結果

問題 No.154 市バス
ユーザー theoldmoon0602theoldmoon0602
提出日時 2016-06-27 06:29:22
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 83,348 KB
実行使用メモリ 4,560 KB
最終ジャッジ日時 2023-09-02 21:16:19
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio,
  std.array,
  std.conv,
  std.string,
  std.algorithm;

bool check(string s)
{
  int cnt = 0;
  int wcnt = 0;
  bool exist = false;
  if (s[$-1] != 'R') {
    return false;
  }
  foreach(char c; s) {
    if (c == 'W') {
      wcnt = 1;
    }
    else if (c == 'G') {
      cnt++;
    }
    else if (c == 'R') {
      if (! (wcnt == 1 && cnt > 1)) {
	return false;
      }
      cnt--;
      wcnt = 0;
      exist = true;
    }
    if (cnt < 0) {
      return false;
    }
  }
  return exist;
}

void main()
{
  int n = readln.chomp.to!int;
  foreach (i; 0..n) {
    bool possible = check(readln.chomp);
    if (possible) {
      writeln("possible");
    }
    else {
      writeln("impossible");
    }
  }
}
0