結果
問題 | No.154 市バス |
ユーザー | Mister |
提出日時 | 2020-04-22 11:22:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 835 bytes |
コンパイル時間 | 827 ms |
コンパイル使用メモリ | 70,972 KB |
最終ジャッジ日時 | 2025-01-09 22:28:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <iostream> #include <algorithm> #include <string> void solve() { std::string s; std::cin >> s; std::reverse(s.begin(), s.end()); int wcnt = 0, gcnt = 0, rcnt = 0, gok = 0; for (char c : s) { if (c == 'W') { ++wcnt; gok = std::max(0, gok - 1); } else if (c == 'G') { ++gok; ++gcnt; } else if (c == 'R') { ++rcnt; } if ((gcnt == 0 && wcnt > 0) || gcnt > rcnt) { std::cout << "impossible" << std::endl; return; } } std::cout << (gok == 0 && gcnt == rcnt ? "possible" : "impossible") << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int q; std::cin >> q; while (q--) solve(); return 0; }