結果
問題 | No.154 市バス |
ユーザー | te-sh |
提出日時 | 2016-08-31 14:42:06 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 736 ms |
コンパイル使用メモリ | 112,128 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 03:59:48 |
合計ジャッジ時間 | 1,411 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
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); }