結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2018-09-25 12:14:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,146 bytes |
コンパイル時間 | 675 ms |
コンパイル使用メモリ | 56,572 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 02:04:25 |
合計ジャッジ時間 | 1,740 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 7 WA * 1 |
ソースコード
#include <iostream>#include <string>#define FOR(i,a,b) for(int i=(a); i<(b); i++)using namespace std;int solve(string str){// 最後から2本目より前のバスが走っている可能性のある系統の最大数int max_n = 0;// 最後から一本目が走ったが、最後の一本は走っていない系統の数int last = 0;FOR(j, 0, str.size()){string c = str.substr(j, 1);if (c == "W"){max_n++;} else if (c == "G"){max_n --;if (max_n < 0) return 0;last += 1;} else{last--;if (last < 0) return 0;}}// lastが0かつRで終わる場合のみあり得るパターンif (last == 0 && str.substr(str.size() - 1, 1) == "R"){return 1;} else {return 0;}}int main(){int t;cin >> t;FOR(i, 0, t){string str;cin >> str;int if_possible = solve(str);if(if_possible){cout << "possible" << endl;} else {cout << "impossible" << endl;}}return 0;}