結果

問題 No.154 市バス
ユーザー oreoreoresanoreoreoresan
提出日時 2018-09-13 13:45:00
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,117 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 63,276 KB
実行使用メモリ 29,568 KB
最終ジャッジ日時 2023-09-13 19:50:44
合計ジャッジ時間 16,320 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 1,608 ms
23,644 KB
testcase_04 AC 1,950 ms
27,632 KB
testcase_05 AC 78 ms
23,576 KB
testcase_06 AC 71 ms
21,280 KB
testcase_07 TLE -
testcase_08 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shibasu
{
    class Program
    {
        private static int IsShibusPossible(string arg)
        {
            string local_arg = arg;

            int W_pos = local_arg.IndexOf("W");
            int G_pos = local_arg.IndexOf("G");
            int R_pos = local_arg.IndexOf("R");

            if (G_pos == -1 && R_pos == -1)
            {
                return 1;
            }

            if (W_pos == -1 || G_pos == -1 || R_pos == -1)
            {
                return -1;
            }

            if(W_pos > G_pos || W_pos > R_pos)
            {
                return -1;
            }

            if (G_pos > R_pos)
            {
                return -1;
            }

            local_arg = local_arg.Remove(local_arg.IndexOf("W"), 1);
            local_arg = local_arg.Remove(local_arg.IndexOf("G"), 1);
            local_arg = local_arg.Remove(local_arg.IndexOf("R"), 1);

            return IsShibusPossible(local_arg);
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int num = int.Parse(s);

            for(int i = 0; i < num; i++)
            {
				string one_data = Console.ReadLine();

				// ひとつもGRが無い
	            int G_pos = one_data.IndexOf("G");
				int R_pos = one_data.IndexOf("R");

				if (G_pos == -1 || R_pos == -1)
				{
					Console.WriteLine("impossible");
					continue;
				}

				// Wの後にGRが無い
	            int W_pos = one_data.LastIndexOf("W");
				string w_data = one_data.Substring(W_pos);
	            G_pos = w_data.IndexOf("G");
				R_pos = w_data.IndexOf("R");

				if (G_pos == -1 || R_pos == -1)
				{
					Console.WriteLine("impossible");
					continue;
				}

                if (IsShibusPossible(one_data) == 1)
                {
                    Console.WriteLine("possible");
                }
                else
                {
                    Console.WriteLine("impossible");
                }

            }
        }
    }
}
0