結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2015-05-26 02:19:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 469 ms |
コンパイル使用メモリ | 57,820 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 07:22:46 |
合計ジャッジ時間 | 1,234 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <iostream> #include <string> #include <algorithm> using namespace std; bool possible(const string& s) { int gCount = 0; for (size_t i = 0; i < s.size(); ++i) { char ch = s[i]; if (ch == 'G') { ++gCount; } else if (ch == 'R') { if (gCount == 0) { return false; } --gCount; } } if (gCount != 0) { return false; } int rootCount = 0; int whiteCount = 0; for (int i = s.size() - 1; i >= 0; --i) { char ch = s[i]; if (ch == 'G') { ++rootCount; } else if (ch == 'W') { if (rootCount == 0) { return false; } whiteCount = min(rootCount, whiteCount + 1); } } if (whiteCount != rootCount) { return false; } return true; } int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { string s; cin >> s; cout << (possible(s) ? "possible" : "impossible") << endl; } return 0; }