結果

問題 No.154 市バス
ユーザー koyumeishikoyumeishi
提出日時 2015-02-18 00:04:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 80,052 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:47:46
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,248 KB
testcase_01 AC 15 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 13 ms
5,376 KB
testcase_04 AC 14 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 12 ms
5,376 KB
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#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;
	}else if(w.size()>0 && r.size()>0 && w.back() > r.back()){
		cout << "impossible" << endl;
	}else{
		cout << "possible" << endl;
	}

}

int main(){
	int T;
	cin >> T;
	while(T--){
		solve();
	}

}
0