結果

問題 No.154 市バス
ユーザー kuuso1kuuso1
提出日時 2016-06-20 00:42:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 3,928 ms
コンパイル使用メモリ 105,596 KB
実行使用メモリ 25,568 KB
最終ジャッジ日時 2023-08-03 11:50:30
合計ジャッジ時間 5,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
23,464 KB
testcase_01 AC 130 ms
25,504 KB
testcase_02 AC 129 ms
25,568 KB
testcase_03 AC 118 ms
25,556 KB
testcase_04 AC 130 ms
25,500 KB
testcase_05 AC 54 ms
21,456 KB
testcase_06 AC 55 ms
21,536 KB
testcase_07 AC 112 ms
25,500 KB
testcase_08 AC 55 ms
23,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		for(;T>0;T--){
			String S=rs();
			var ret = Check(S);
			Console.WriteLine(ret?"possible":"impossible");
		}
	}
	int T;
	public Sol(){
		T = ri();
	}
	
	
	static bool Check(String S){
		
		int wAll = S.Count(c => c == 'W');
		int gAll = S.Count(c => c == 'G');
		int rAll = S.Count(c => c == 'R');
		
		if(gAll != rAll)return false;
		if(wAll < rAll)return false;
		
		int p = 0;
		int N = S.Length;
		for(int i=0;i<N;i++){
			if(S[i] == 'W')continue;
			if(S[i] == 'G'){
				p++;
			}
			if(S[i] == 'R'){
				p--;
				if(p<0){
					return false;
				}
			}
		}
		
		int w = 0;
		int gRest = gAll;
		for(int i=0;i<N;i++){
			if(S[i] == 'R')continue;
			if(S[i] == 'W'){
				w++;
			}
			if(S[i] == 'G'){
				gRest--;
				if(w>gRest){
					w = gRest;
				} else {
					w--;
				}
				if(w<0)return false;
			}
		}
		
		if(w>0) return false;
		
		return true;
		
	}
	
	
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0