結果

問題 No.154 市バス
ユーザー te-shte-sh
提出日時 2016-08-31 14:42:06
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 99,316 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:44:42
合計ジャッジ時間 1,392 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.bitmanip, std.random;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto t = readln.chomp.to!int;

  foreach (_; 0..t)
    writeln(calc(readln.chomp) ? "possible" : "impossible");
}

bool calc(string s)
{
  auto a = 0, b = 0, c = false, d = 0;

  foreach_reverse (t; s) {
    switch (t) {
    case 'R':
      a += 1;
      break;
    case 'G':
      b += 1;
      c = true;
      d -= 1;
      if (a < b) return false;
      break;
    case 'W':
      if (!c) return false;
      else if (d < 0) d += 1;
      break;
    default: assert(0);
    }
  }

  return (a == b && d == 0);
}
0