結果

問題 No.154 市バス
ユーザー te-shte-sh
提出日時 2016-08-31 01:17:08
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 693 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 99,300 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:41:54
合計ジャッジ時間 1,515 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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) {
    auto s = readln.chomp;

    writeln(calc(s) ? "possible" : "impossible");
  }
}

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

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

  return a <= d;
}
0