結果

問題 No.154 市バス
ユーザー 明智重蔵明智重蔵
提出日時 2016-07-02 17:14:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,399 bytes
コンパイル時間 3,034 ms
コンパイル使用メモリ 107,180 KB
実行使用メモリ 24,704 KB
最終ジャッジ日時 2024-04-21 09:49:32
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
24,576 KB
testcase_01 AC 69 ms
24,576 KB
testcase_02 AC 69 ms
24,448 KB
testcase_03 AC 66 ms
24,448 KB
testcase_04 AC 68 ms
24,704 KB
testcase_05 AC 26 ms
18,688 KB
testcase_06 AC 28 ms
18,688 KB
testcase_07 AC 64 ms
24,704 KB
testcase_08 AC 26 ms
18,432 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.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("WWWWWWWWWGR");
            WillReturn.Add("WWWWGWGRR");
            WillReturn.Add("WWWWWWWWWWWWWWGRRG");
            WillReturn.Add("WGRWGR");
            WillReturn.Add("WWWWWWWWWWWWWWWWWGGWGWGGWGWGGGWGG");
            //possible
            //possible
            //impossible
            //possible
            //impossible
            //1つ目:1つの系統のバスしかありません
            //2つ目:2つの系統のバスがあります
            //3つ目:片方の系統において,
            //       終バスの後に緑のライトのバスが走っている感じでなんかおかしいです.
            //4つ目:1つの系統の終バスが終わってから,
            //      もう一方の系統が走り始めるなんてこともあるんですね.
            //5つ目:終バスがないなんてことはない
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        foreach (string EachStr in InputList.Skip(1)) {
            if (IsPossible(EachStr)) Console.WriteLine("possible");
            else Console.WriteLine("impossible");
        }
    }

    static bool IsPossible(string pStr)
    {
        //正規表現RBW+を受信するオートマンの、現在位置ごとの件数
        int RCnt = 0;
        int GCnt = 0;
        int WCnt = 0;

        foreach (char CurrChar in pStr.Reverse()) {
            if (CurrChar == 'R') {
                RCnt++;
            }
            else if (CurrChar == 'G') {
                if (RCnt == 0) return false;
                RCnt--; GCnt++;
            }
            else if (CurrChar == 'W') {
                if (GCnt > 0) {
                    GCnt--; WCnt++;
                }
                else if (WCnt == 0) return false;
            }
        }
        if (RCnt > 0) return false;
        if (GCnt > 0) return false;
        return true;
    }
}
0