結果

問題 No.274 The Wall
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-03 21:27:53
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,469 bytes
コンパイル時間 5,064 ms
コンパイル使用メモリ 111,056 KB
実行使用メモリ 24,148 KB
最終ジャッジ日時 2023-09-26 02:38:03
合計ジャッジ時間 5,287 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
23,776 KB
testcase_01 AC 64 ms
23,868 KB
testcase_02 AC 64 ms
21,980 KB
testcase_03 AC 64 ms
19,920 KB
testcase_04 AC 64 ms
21,892 KB
testcase_05 AC 65 ms
21,892 KB
testcase_06 AC 65 ms
23,868 KB
testcase_07 AC 64 ms
23,916 KB
testcase_08 AC 65 ms
23,936 KB
testcase_09 AC 64 ms
21,968 KB
testcase_10 AC 64 ms
20,004 KB
testcase_11 AC 67 ms
22,116 KB
testcase_12 AC 67 ms
21,908 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 66 ms
22,040 KB
testcase_17 AC 66 ms
21,856 KB
testcase_18 AC 66 ms
21,856 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 67 ms
19,976 KB
testcase_23 AC 67 ms
21,844 KB
testcase_24 WA -
testcase_25 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.Linq;

class Program
{
    static string InputPattern = "Input5";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4 6");
            WillReturn.Add("5 5");
            WillReturn.Add("2 3");
            WillReturn.Add("4 4");
            WillReturn.Add("1 1");
            //YES
            //問題文中の良い壁の例と同じ。
            //どのブロックも180度回転させずに積めば良い壁になる。
            //0番目のブロックを180度回転させても良い壁には変わりない。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4 6");
            WillReturn.Add("3 5");
            WillReturn.Add("3 4");
            WillReturn.Add("4 4");
            WillReturn.Add("1 2");
            //NO
            //問題文中の悪い壁の例と同じ。
            //180度回転をどのように使っても良い壁はできない。
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("2 4");
            WillReturn.Add("0 1");
            WillReturn.Add("0 1");
            //YES
            //どちらかのブロックを180度回転させて積めば良い壁になる
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("5 10");
            WillReturn.Add("8 8");
            WillReturn.Add("0 0");
            WillReturn.Add("2 4");
            WillReturn.Add("2 3");
            WillReturn.Add("8 8");
            //YES
            //良い壁にできます
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct BlookDef
    {
        internal int L;
        internal int R;
        internal int KaitenL;
        internal int KaitenR;
    }

    static int M;

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = { };

        Action<string> SplitAct = (pStr) =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        M = wkArr[1];

        var BlookList = new List<BlookDef>();
        for (int I = 1; I <= InputList.Count - 1; I++) {
            SplitAct(InputList[I]);
            BlookList.Add(CreateBlockInfo(wkArr[0], wkArr[1]));
        }
        Console.WriteLine(CanCreateGoodWall(BlookList) ? "YES" : "NO");
    }

    //ブロック情報を作成
    static BlookDef CreateBlockInfo(int pL, int pR)
    {
        BlookDef WillReturn;

        int NewL = M - 1 - pR;
        int NewR = M - 1 - pL;

        //L < KaitenL とする
        if (NewL < pL) {
            WillReturn.L = NewL; WillReturn.R = NewR;
            WillReturn.KaitenL = pL; WillReturn.KaitenR = pR;
        }
        else {
            WillReturn.L = pL; WillReturn.R = pR;
            WillReturn.KaitenL = NewL; WillReturn.KaitenR = NewR;
        }
        return WillReturn;
    }

    //良い壁を作成できるかを返す
    static bool CanCreateGoodWall(List<BlookDef> pBlookList)
    {
        var IsPinkArr = new System.Collections.BitArray(M);

        foreach (BlookDef EachBlock in pBlookList) {

            //左に詰めて置けるなら、置く
            bool CamSetLeft = true;
            for (int I = EachBlock.L; I <= EachBlock.R; I++) {
                if (IsPinkArr[I]) {
                    CamSetLeft = false; break;
                }
            }
            if (CamSetLeft) {
                for (int I = EachBlock.L; I <= EachBlock.R; I++) {
                    IsPinkArr[I] = true;
                }
                continue;
            }

            //左に詰めて置けないなら、180度回転させて、右に置く
            bool CamSetRight = true;
            for (int I = EachBlock.KaitenL; I <= EachBlock.KaitenR; I++) {
                if (IsPinkArr[I]) {
                    CamSetRight = false; break;
                }
            }
            if (CamSetRight) {
                for (int I = EachBlock.KaitenL; I <= EachBlock.KaitenR; I++) {
                    IsPinkArr[I] = true;
                }
                continue;
            }

            //ブロックを配置できなかったらNG
            return false;
        }
        return true;
    }
}
0