結果

問題 No.154 市バス
ユーザー 14番14番
提出日時 2016-07-19 01:12:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 104,184 KB
実行使用メモリ 29,000 KB
最終ジャッジ日時 2023-08-03 11:56:37
合計ジャッジ時間 3,279 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
26,920 KB
testcase_01 AC 69 ms
24,796 KB
testcase_02 AC 71 ms
29,000 KB
testcase_03 AC 69 ms
26,972 KB
testcase_04 AC 69 ms
27,016 KB
testcase_05 AC 54 ms
22,704 KB
testcase_06 AC 53 ms
20,860 KB
testcase_07 AC 66 ms
27,012 KB
testcase_08 AC 53 ms
20,724 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