結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-07-20 19:57:16 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,659 bytes |
| コンパイル時間 | 988 ms |
| コンパイル使用メモリ | 109,312 KB |
| 実行使用メモリ | 48,020 KB |
| 最終ジャッジ日時 | 2024-07-08 11:19:41 |
| 合計ジャッジ時間 | 7,847 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 29 |
コンパイルメッセージ
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("5");
}
else if (InputPattern == "Input2") {
WillReturn.Add("11");
}
else if (InputPattern == "Input3") {
WillReturn.Add("4");
}
else if (InputPattern == "Input4") {
WillReturn.Add("10000");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
//すごろくのマスの数
int MasuCnt = int.Parse(InputList[0]);
//各マスの1のビット数の配列
int[] BitCntArr = new int[MasuCnt];
for (int I = 1; I <= BitCntArr.GetUpperBound(0); I++) {
int wkBitCnt = Convert.ToString(I, 2).ToCharArray().Count(X => X == '1');
BitCntArr[I] = wkBitCnt;
}
//移動回数と訪問済マスのDict
var VisitedArrDict = new Dictionary<int, bool[]>();
for (int MaxMoveCnt = 1; MaxMoveCnt <= MasuCnt; MaxMoveCnt++) {
bool[] VisitedArr = new bool[MasuCnt + 1];
VisitedArr[1] = true;
for (int CurrMoveCnt = 2; CurrMoveCnt <= MaxMoveCnt; CurrMoveCnt++) {
var VisitedIndSet = new HashSet<int>();
for (int I = 1; I <= VisitedArr.GetUpperBound(0); I++) {
if (VisitedArr[I] == false) continue;
int wkLeftInd = I - BitCntArr[I];
int wkRightInd = I + BitCntArr[I];
if (wkLeftInd >= 1) VisitedIndSet.Add(wkLeftInd);
if (wkRightInd <= MasuCnt) VisitedIndSet.Add(wkRightInd);
}
foreach (int EachVisitedInd in VisitedIndSet) {
VisitedArr[EachVisitedInd] = true;
}
}
if (VisitedArr[MasuCnt]) {
Console.WriteLine(MaxMoveCnt);
return;
}
//移動回数が1少ない場合と、訪問済マスが同じなら、解なし
VisitedArrDict.Add(MaxMoveCnt, VisitedArr);
if (MaxMoveCnt >= 2) {
if (VisitedArrDict[MaxMoveCnt - 1].SequenceEqual(VisitedArrDict[MaxMoveCnt])) {
Console.WriteLine(-1);
}
}
}
}
}
明智重蔵