結果

問題 No.154 市バス
ユーザー 184184
提出日時 2015-02-18 00:15:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 51,960 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:51:29
合計ジャッジ時間 1,035 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,248 KB
testcase_01 AC 13 ms
5,376 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 13 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         int t;scanf("%d",&t);
      |               ~~~~~^~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%s",s);
      |                 ~~~~~^~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

//namaega184
  
int main(){
	int t;scanf("%d",&t);
	char s[1001];
	for(int i=0;i<t;i++){
		scanf("%s",s);
		int len=strlen(s);
		int w=0,g=0,r=0;
		int a=0,gg=0,rr=0;
		char lst;
		for(int j=len-1;j>=0;j--){ 
			if(s[j]=='W'){
				w++;
				if(r==0||g==0){a=1;break;}
			}
			else if(s[j]=='G'){
				g++;
				if( g>r){
					a=1;
					break;
				}
			}
			else{ 
				r++;
				if( g>r){
					a=1;
					break;
				} 
			} 
		} 
		if(a||!r||!g){printf("impossible\n");continue;}
		w=0,g=0,r=0;
		a=0,gg=0,rr=0;
		for(int j=0;j<len;j++){ 
			if(s[j]=='W')w++;
			else if(s[j]=='G'){
				g++;
				if(g>w){
					a=1;
					break;
				}
			}
			else{ 
				r++;
				if(r>w||r>g){
					a=1;
					break;
				} 
			} 
		} 
		if(a||!r||!g)printf("impossible\n");
		else printf("possible\n");
	}
	
	return 0;
	 
}
0