結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2020-09-25 06:18:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 807 bytes |
コンパイル時間 | 1,726 ms |
コンパイル使用メモリ | 195,540 KB |
最終ジャッジ日時 | 2025-01-14 20:28:28 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) bool check(const string &s) { int g = count(s.begin(), s.end(), 'G'); int r = count(s.begin(), s.end(), 'R'); int w = count(s.begin(), s.end(), 'W'); if (!g || !r || !w) return false; if (g != r) return false; if (w < g) return false; if (s.find_last_of("W") > s.find_last_of("G")) return false; int stk = 0; for (char c: s) { if (c == 'G') ++stk; else if (c == 'R') { if (--stk < 0) return false; } } return !stk; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { string s; cin >> s; if (check(s)) cout << "possible" << endl; else cout << "impossible" << endl; } return 0; }