結果

問題 No.154 市バス
ユーザー theoldmoon0602theoldmoon0602
提出日時 2016-06-27 06:23:15
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 587 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 85,176 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:15:52
合計ジャッジ時間 1,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

bool check(string s)
{
  int cnt = 0;
  bool exist = false;
  if (s[$-1] != 'R') {
    return false;
  }
  foreach(char c; s) {
    if (c == 'G') {
      cnt++;
    }
    else if (c == 'R') {
      cnt--;
      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