結果
問題 | No.154 市バス |
ユーザー |
![]() |
提出日時 | 2015-02-18 00:10:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 1,095 bytes |
コンパイル時間 | 878 ms |
コンパイル使用メモリ | 80,488 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 06:35:48 |
合計ジャッジ時間 | 1,429 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’: main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%s", c); | ~~~~~^~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> using namespace std; void solve(){ char c[2000]; scanf("%s", c); string s = c; deque<int> w; deque<int> g; deque<int> r; int n = s.size(); for(int i=0; i<n; i++){ if(s[i] == 'W'){ w.push_back(i); }else if(s[i] == 'G'){ if(w.size() > 0){ w.pop_front(); g.push_back(i); }else{ cout << "impossible" << endl; return; } }else if(s[i] == 'R'){ if(g.size() > 0){ g.pop_front(); r.push_back(i); }else{ cout << "impossible" << endl; return; } } } if(g.size()>0 || r.size()==0){ cout << "impossible" << endl; return; } if(w.size()>0 && r.size()>0 && w.back() > r.back()){ cout << "impossible" << endl; return; } for(int i=r.back(); i>=0; i--){ if(s[i] == 'G') break; else if(s[i] == 'W'){ cout << "impossible" << endl; return; } } cout << "possible" << endl; } int main(){ int T; cin >> T; while(T--){ solve(); } }