結果

問題 No.154 市バス
ユーザー 14番14番
提出日時 2016-07-19 01:12:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 105,472 KB
実行使用メモリ 22,016 KB
最終ジャッジ日時 2024-04-21 09:51:45
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
22,016 KB
testcase_01 AC 40 ms
21,760 KB
testcase_02 AC 39 ms
22,016 KB
testcase_03 AC 39 ms
21,888 KB
testcase_04 AC 40 ms
22,016 KB
testcase_05 AC 22 ms
17,920 KB
testcase_06 AC 22 ms
17,792 KB
testcase_07 AC 35 ms
21,760 KB
testcase_08 AC 22 ms
18,048 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.Generic;
using System.Text;
using System.Linq;

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

    private bool GetAns(String inpt) {
        int rCount = 0;
        int gCount = 0;
        int wCount = 0;

        for(int i=inpt.Length - 1; i>=0; i--) {
            if(inpt[i] == 'R') {
                rCount++;
            } else if(inpt[i] == 'G') {
                if(rCount == 0) {
                    return false;
                }
                rCount--;
                gCount++;
            } else {
                if(gCount == 0) {
                    if(wCount == 0) {
                        return false;
                    }
                } else {
                    gCount--;
                    wCount++;
                }
            }
        }
        if(rCount > 0 || gCount > 0) {
            return false;
        }
        return true;

    }


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




 
";
        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