結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2020-05-12 01:49:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 2,255 ms |
コンパイル使用メモリ | 196,600 KB |
最終ジャッジ日時 | 2025-01-10 10:31:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | int q; scanf("%d",&q); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;bool solve(string s){int n=s.length();vector<int> a;for(int i=n-1;i>=0;i--){if(s[i]=='R'){a.emplace_back(0);}else if(s[i]=='G'){bool ok=false;rep(j,a.size()) if(a[j]==0) {a[j]++;ok=true;break;}if(!ok) return false;}else{ // 'W'bool ok=false;rep(j,a.size()) if(a[j]==1) {a[j]++;ok=true;break;}if(!ok){rep(j,a.size()) if(a[j]>=2) {a[j]++;ok=true;break;}}if(!ok) return false;}}rep(j,a.size()) if(a[j]<=1) return false;return true;}int main(){int q; scanf("%d",&q);rep(_,q){string s; cin>>s;puts(solve(s)?"possible":"impossible");}return 0;}