結果

問題 No.274 The Wall
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-03 22:25:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 4,562 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 107,704 KB
実行使用メモリ 24,072 KB
最終ジャッジ日時 2023-09-04 02:06:21
合計ジャッジ時間 5,044 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,904 KB
testcase_01 AC 62 ms
21,920 KB
testcase_02 AC 62 ms
21,924 KB
testcase_03 AC 65 ms
24,012 KB
testcase_04 AC 63 ms
19,992 KB
testcase_05 AC 64 ms
23,976 KB
testcase_06 AC 64 ms
24,072 KB
testcase_07 AC 63 ms
21,932 KB
testcase_08 AC 64 ms
23,916 KB
testcase_09 AC 62 ms
21,816 KB
testcase_10 AC 62 ms
24,060 KB
testcase_11 AC 66 ms
24,056 KB
testcase_12 AC 66 ms
24,020 KB
testcase_13 AC 64 ms
24,012 KB
testcase_14 AC 65 ms
21,900 KB
testcase_15 AC 65 ms
21,976 KB
testcase_16 AC 65 ms
21,836 KB
testcase_17 AC 66 ms
21,972 KB
testcase_18 AC 65 ms
21,908 KB
testcase_19 AC 66 ms
21,884 KB
testcase_20 AC 66 ms
23,944 KB
testcase_21 AC 66 ms
19,940 KB
testcase_22 AC 67 ms
23,956 KB
testcase_23 AC 67 ms
23,956 KB
testcase_24 AC 69 ms
24,020 KB
testcase_25 AC 66 ms
21,832 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.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]));
        }
        BlookList.Sort((A, B) => A.L.CompareTo(B.L));
        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 (pL < NewL) {
            WillReturn.L = pL; WillReturn.R = pR;
            WillReturn.KaitenL = NewL; WillReturn.KaitenR = NewR;
        }
        else {
            WillReturn.L = NewL; WillReturn.R = NewR;
            WillReturn.KaitenL = pL; WillReturn.KaitenR = pR;
        }
        return WillReturn;
    }

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

        foreach (BlookDef EachBlock in pBlookList) {

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

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

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