結果

問題 No.154 市バス
ユーザー matsumatsu
提出日時 2018-09-10 14:26:13
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,816 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 104,912 KB
実行使用メモリ 24,952 KB
最終ジャッジ日時 2023-08-28 14:14:34
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
22,736 KB
testcase_01 AC 61 ms
20,844 KB
testcase_02 AC 61 ms
20,628 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 53 ms
20,692 KB
testcase_06 AC 53 ms
20,872 KB
testcase_07 AC 59 ms
18,624 KB
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace bus
{
    class Program
    {
        static void Main(string[] args)
        {
            // テストケースの数 整数 "T"
            int Num_T = int.Parse(Console.ReadLine());

            // テストケース文字列 "S"
            string str_S = Console.ReadLine();

            // テストケース文字列を1文字ずつ判定
            for (int i = 0; i < Num_T; i++)
            {
                Console.WriteLine(judgingLight(str_S));
            }
        }

        static string judgingLight(string str)
        {
            int wht = 0;    // 白色カウント
            int grn = 0;    // 緑色カウント
            int red   = 0;  // 赤色カウント
            char pre = ' '; // 直前の色を記憶

            // 一文字ずつ検索する
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == 'W')
                {
                    wht++;
                }
                if (str[i] == 'G')
                {
                    grn++;
                }
                if (str[i] == 'R')
                {
                    red++;
                }
                else
                {
                    pre = str[i];
                }

                // "白 < 緑"もしくは"緑 < 赤" になるタイミングは絶対に存在しない
                if (wht < grn || grn < red)
                {
                    return "impossible";
                }
            }

            // 最後の直前が "G(緑)" かつ "緑と赤の数が同じ"ときのみ存在する
            if (pre == 'G' && grn == red)
            {
                return "possible";
            }
            else
            {
                return "impossible";
            }
        }
    }
}
0