結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-08-31 19:14:30 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,041 bytes |
| コンパイル時間 | 964 ms |
| コンパイル使用メモリ | 115,828 KB |
| 実行使用メモリ | 44,544 KB |
| 最終ジャッジ日時 | 2024-07-18 17:11:06 |
| 合計ジャッジ時間 | 4,964 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 TLE * 1 -- * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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
}
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
}
else if (InputPattern == "Input3") {
WillReturn.Add("2 4");
WillReturn.Add("0 1");
WillReturn.Add("0 1");
//YES
}
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 LRDef
{
internal int L;
internal int R;
}
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 LRList = new List<LRDef>();
for (int I = 1; I <= InputList.Count - 1; I++) {
SplitAct(InputList[I]);
LRList.Add(new LRDef() { L = wkArr[0], R = wkArr[1] });
}
LRList.Sort((A, B) =>
{
int wkInt1 = A.L.CompareTo(B.L);
if (wkInt1 != 0) return wkInt1;
return A.R.CompareTo(B.R);
});
Console.WriteLine(ExecDFS(LRList) ? "YES" : "NO");
}
struct JyoutaiDef
{
internal int CurrY;
internal System.Collections.BitArray BanArr;
//internal string FillLog;
}
//深さ優先探索で解の有無を判定する
static bool ExecDFS(List<LRDef> pLRList)
{
var stk = new Stack<JyoutaiDef>();
JyoutaiDef WillPush;
WillPush.CurrY = 0;
WillPush.BanArr = new System.Collections.BitArray(M);
//WillPush.FillLog = "";
stk.Push(WillPush);
while (stk.Count > 0) {
JyoutaiDef Popped = stk.Pop();
//クリア判定
if (Popped.CurrY > pLRList.Count - 1) {
//Console.WriteLine(Popped.FillLog);
return true;
}
Action<LRDef> PushSyori = (pLR) =>
{
for (int I = pLR.L; I <= pLR.R; I++) {
if (Popped.BanArr[I]) return;
}
WillPush.CurrY = Popped.CurrY + 1;
WillPush.BanArr = new System.Collections.BitArray(Popped.BanArr);
for (int I = pLR.L; I <= pLR.R; I++) {
WillPush.BanArr[I] = true;
}
//WillPush.FillLog = Popped.FillLog + string.Format("{0}から{1}がピンクになります",
// pLR.L, pLR.R);
//WillPush.FillLog += Environment.NewLine;
stk.Push(WillPush);
};
PushSyori(pLRList[Popped.CurrY]);
if (Popped.CurrY > 0) { //1個目は回転不可
PushSyori(DeriveKaitenLR(pLRList[Popped.CurrY]));
}
}
return false;
}
//180度回転したLRを返す
static LRDef DeriveKaitenLR(LRDef pLR)
{
int NewL = M - 1 - pLR.R;
int NewR = M - 1 - pLR.L;
return new LRDef() { L = NewL, R = NewR };
}
}
明智重蔵