結果
問題 | No.154 市バス |
ユーザー | k |
提出日時 | 2020-09-25 06:23:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 812 bytes |
コンパイル時間 | 1,954 ms |
コンパイル使用メモリ | 195,408 KB |
最終ジャッジ日時 | 2025-01-14 20:28:40 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#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 (s.find_last_of("W") > s.find_last_of("G")) return false; int p = 0, q = 0; for (char c: s) { if (c == 'W') ++p; else if (c == 'G') { if (--p < 0) return false; ++q; } else { if (--q < 0) return false; } } return !q; } 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; }