結果

問題 No.154 市バス
ユーザー syoken_desukasyoken_desuka
提出日時 2015-02-20 12:49:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 7,166 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 114,956 KB
実行使用メモリ 33,348 KB
最終ジャッジ日時 2024-04-21 08:12:41
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
28,996 KB
testcase_01 AC 61 ms
28,752 KB
testcase_02 AC 61 ms
31,044 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 50 ms
31,044 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;
using System.Collections.Generic;
using System.Text;
using sc = Scanner;
using System.Collections;


class Program
{
    static void Main(string[] args)
    {
        Solve();
        /*
#if DEBUG
        Console.WriteLine("終了するにはなにかキーを押して下さい...");
        Console.ReadKey();
#endif
         * */
    }

    static void Solve()
    {
        int n = sc.NextInt();
        string[] quary = new string[n];
        for (int i = 0; i < n; i++)
        {
            quary[i] = Console.ReadLine();
        }
        for (int i = 0; i < n; i++)
        {
            string busData = quary[i];
            int checkW = 0;
            int checkR = 0;
            int checkG = 0;
            int allW = 0;
            int allG =0;
            int allR = 0;
            for (int j = 0; j < busData.Length; j++)
			{
                switch(busData[j])
                {
                    case 'W':
                        allW++;
                        break;
                    case 'G':
                        allG++;
                        break;
                    case 'R':
                        allR++;
                        break;
                    default:
                        break;
                }
			}
            for (int j = 0; j < busData.Length; j++)
            {
                if (busData[j] == 'W')
                {
                    if (checkG == allG)
                    {
                        Console.WriteLine("impposible");
                        break;
                    }
                    checkW++;
                }
                if (busData[j] == 'G')
                    checkG++;
                if (busData[j] == 'R')
                {
                    checkR++;
                    if (checkR > checkG)
                    {
                        Console.WriteLine("impposible");
                        break;
                    }
                }
                //最後の終了条件
                if (j == busData.Length-1)
                {
                    if (busData[j] == 'R' && checkG == checkR && checkW >= checkR)
                    {
                        Console.WriteLine("possible");
                    }
                    else
                        Console.WriteLine("impossible");
                }
            }
        }
    }
}

/// <summary>
/// ・一般的なデータ構造のオブジェクトT
/// ・Icomparableを持った「新たなクラスを生成すること無く」比較方法の動的化
/// を目的とした優先度付きキュー,comparison にCompareToを入れる
/// 1回あたりの計算量はPop PushともにO(logn)
/// </summary>
/// <typeparam name="T"></typeparam>
class PriorityQueue<T>
{
    ArrayList array;

    public int Count { get{return array.Count;}}

    Comparison<T> comparison;

    /// <summary>
    /// コンストラクタ
    /// </summary>
    /// <param name="comparison">Tに対する比較方向を示すデリゲート, (a,b)のとき返り値intに a_int - b_int (a > b) なら昇順,逆なら降順</param>
    public PriorityQueue(Comparison<T> comparison)
    {
        this.comparison = comparison;
        array = new ArrayList();
    }

    /// <summary>
    /// ヒープ化されている配列リストに新しい要素を追加する。
    /// </summary>
    /// <param name="array">対象の配列リスト</param>
    private void PushHeap(T elem)
    {
        int n = array.Count;
        array.Add(elem);

        while (n != 0)
        {
            int i = (n - 1) / 2;
            // 親と値を入れ替え
            if (comparison((T)array[n], (T)array[i]) < 0)
            {
                T tmp = (T)array[n]; array[n] = array[i]; array[i] = tmp;
            }
            n = i;
        }
    }

    /// <summary>
    /// ヒープから指定した値を削除する。
    /// </summary>
    /// <param name="array">対象の配列リスト</param>
    private T PopHeap()
    {
        if (array.Count == 0)
            throw new IndexOutOfRangeException("要素が0のキューに要素を取り出す命令がおこなわれました");
        int n = array.Count - 1;
        T returnItem = (T)array[0];
        array[0] = array[n];
        array.RemoveAt(n);

        for (int i = 0, j; (j = 2 * i + 1) < n; )
        {
            // 値の大きい方の子を選ぶ
            if ((j != n - 1) && (comparison((T)array[j],(T)array[j+1]) > 0))
                j++;
            // 子と値を入れ替え
            if (comparison((T)array[i], (T)array[j]) > 0)
            {
                T tmp = (T)array[j]; array[j] = array[i]; array[i] = tmp;
            }
            i = j;
        }
        return returnItem;
    }





    /// <summary>
    /// 要素のプッシュ.
    /// </summary>
    /// <param name="elem">挿入したい要素</param>
    public void Push(T elem)
    {
        PushHeap(elem);
    }


    /// <summary>
    /// 要素をポップ.出したデータはコレクションの中から消える
    /// </summary>
    /// <returns></returns>
    public T Pop()
    {
        return PopHeap();
    }

    /// <summary>
    /// 要素を全て消去する
    /// </summary>
    public void Clear()
    {
        array.Clear();
    }
}



public static class Scanner
{
    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return int.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return double.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return long.Parse(tmp);
    }
    public static double[] NextDoubleArray()
    {

        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}
0