結果

問題 No.154 市バス
ユーザー mori_chibimori_chibi
提出日時 2017-08-23 10:40:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 2,919 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 113,348 KB
実行使用メモリ 23,168 KB
最終ジャッジ日時 2024-04-21 10:21:45
合計ジャッジ時間 5,898 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 557 ms
22,912 KB
testcase_01 AC 558 ms
22,912 KB
testcase_02 AC 559 ms
23,168 KB
testcase_03 AC 492 ms
23,040 KB
testcase_04 AC 546 ms
23,040 KB
testcase_05 AC 20 ms
17,792 KB
testcase_06 AC 19 ms
17,408 KB
testcase_07 AC 666 ms
22,912 KB
testcase_08 AC 21 ms
17,536 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.IO;

namespace Citybus
{
    class Program
    {
        static void Main(string[] args)
        {
            bool possible;
            char[] charary;
            Tube TestTube = new Tube();
            int lines = int.Parse(Console.ReadLine());
            List<string> line = new List<string>();
            //Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
            for (int i = 0; i < lines; i++)
            {
                line.Add(Console.ReadLine());
            }
            for (int i = 0; i < lines; i++)
            {
                possible = true;
                charary = line[i].ToCharArray();
                for (int j = charary.Length - 1; j > -1 && possible; j--)
                {
                    switch (charary[j])
                    {
                        case 'R': TestTube.AddRed(); break;
                        case 'G': possible = TestTube.AddGreen();  break;
                        case 'W': possible = TestTube.AddWhite(); break;
                    }
                }
                if( possible && TestTube.Inspect() )
                {
                    Console.WriteLine("possible");
                }
                else
                {
                    Console.WriteLine("impossible");
                }
                TestTube.Clear();
            }
        }
        private class Tube : List<byte>
        {
            const byte color_r = 1;
            const byte color_g = 2;
            const byte color_w = 4;
            const byte color_rg = 3;
            const byte color_rgw = 7;
            public void AddRed()
            {
                this.Add(color_r);
            }
            public bool AddGreen()
            {
                for(int i = 0; i < this.Count; i++)
                {
                    if (this[i] == color_r)
                    {
                        this[i] += color_g;
                        return true;
                    }
                };
                return false;
            }
            public bool AddWhite()
            {
                bool r = false;
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i] == color_rg)
                    {
                        this[i] += color_w;
                        return true;
                    }
                    if (this[i] == color_rgw)
                    {
                        r = true;
                    }
                }
                return r;
            }
            public bool Inspect()
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i] != color_rgw)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
    }
}
0