結果
問題 | No.154 市バス |
ユーザー | kuuso1 |
提出日時 | 2016-06-20 00:42:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 110 ms / 2,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 1,458 ms |
コンパイル使用メモリ | 111,128 KB |
実行使用メモリ | 28,600 KB |
最終ジャッジ日時 | 2024-04-21 09:45:53 |
合計ジャッジ時間 | 3,059 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
28,596 KB |
testcase_01 | AC | 109 ms
28,344 KB |
testcase_02 | AC | 109 ms
28,484 KB |
testcase_03 | AC | 95 ms
28,468 KB |
testcase_04 | AC | 109 ms
28,600 KB |
testcase_05 | AC | 33 ms
26,528 KB |
testcase_06 | AC | 32 ms
24,480 KB |
testcase_07 | AC | 91 ms
28,472 KB |
testcase_08 | AC | 34 ms
24,396 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));} }