結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2020-01-18 18:23:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,679 bytes |
コンパイル時間 | 2,306 ms |
コンパイル使用メモリ | 199,980 KB |
最終ジャッジ日時 | 2025-01-08 20:08:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define DEBUG void is_possible(string s){ stack<int> bus, bus2; reverse(s.begin(), s.end()); string result = "possible"; // cout << s << endl; bool white_ok = false; rep(i, s.length()){ if (white_ok){ if (s[i] == 'R') bus.push(1); else if (s[i] == 'G'){ bus2.push(1); if (!bus.empty()) bus.pop(); else{ result = "impossible"; break; } } else if (s[i] == 'W' && !bus2.empty()){ bus2.pop(); } } else{ if (s[i] == 'R'){ bus.push(1); } else if (s[i] == 'G'){ bus2.push(1); if (!bus.empty()){ bus.pop(); white_ok = true; } else{ result = "impossible"; break; } } else if (s[i] == 'W'){ result = "impossible"; break; } } } if (!bus.empty() || !bus2.empty()) result = "impossible"; cout << result << endl; return; } int main() { int n; string s; cin >> n; rep(i, n){ cin >> s; is_possible(s); } return 0; }