結果

問題 No.154 市バス
ユーザー 14番14番
提出日時 2016-07-19 00:55:13
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,503 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 113,208 KB
実行使用メモリ 41,992 KB
最終ジャッジ日時 2024-04-21 09:51:28
合計ジャッジ時間 7,713 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int queryCount = int.Parse(Reader.ReadLine());
        for(int i=0; i<queryCount; i++) {
            if(this.GetAns(Reader.ReadLine())) {
                Console.WriteLine("possible");
            } else {
                Console.WriteLine("impossible");
            }
        }

    }

    private bool GetAns(String inpt) {
        int rCount = inpt.Count(a=>a=='R');
        int gCount = inpt.Count(a=>a=='G');
        int wCount = inpt.Count(a=>a=='W');
        if(rCount != gCount) {
            return false;
        }
        if(wCount < rCount) {
            return false;
        }
        int fIdx = Math.Max(0, inpt.IndexOf('G') - gCount);

        Dictionary<int, char> rosen = new Dictionary<int, char>();
        char[] rev = inpt.Substring(fIdx).Reverse().ToArray();
        for(int i=0; i<rev.Length; i++) {
            if(rev[i] == 'R') {
                rosen.Add(rosen.Count, rev[i]);
            } else if(rev[i] == 'G') {
                if(rosen.Count(a=>a.Value == 'R') == 0) {
                    return false;
                }
                int idx = rosen.First(a=>a.Value == 'R').Key;
                rosen[idx] = 'G';
            } else {
                if(rosen.Count(a=>a.Value == 'G') == 0) {
                    if(rosen.Count(a=>a.Value == 'W') == 0) {
                        return false;
                    }
                } else {
                    int idx = rosen.First(a=>a.Value == 'G').Key;
                    rosen[idx] = 'W';
                }
            }
        }
        return !(rosen.Count(a=>a.Value != 'W') > 0);
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


5
WWWWWWWWWGR
WWWWGWGRR
WWWWWWWWWWWWWWGRRG
WGRWGR
WWWWWWWWWWWWWWWWWGGWGWGGWGWGGGWGG


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }

    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0