結果

問題 No.154 市バス
ユーザー 明智重蔵明智重蔵
提出日時 2016-07-02 17:14:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 2,399 bytes
コンパイル時間 3,272 ms
コンパイル使用メモリ 106,680 KB
実行使用メモリ 29,484 KB
最終ジャッジ日時 2023-08-03 11:54:07
合計ジャッジ時間 5,082 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
29,400 KB
testcase_01 AC 101 ms
27,416 KB
testcase_02 AC 102 ms
29,484 KB
testcase_03 AC 98 ms
29,408 KB
testcase_04 AC 105 ms
29,448 KB
testcase_05 AC 57 ms
23,528 KB
testcase_06 AC 59 ms
21,524 KB
testcase_07 AC 96 ms
29,436 KB
testcase_08 AC 56 ms
23,528 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