結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-25 02:14:27 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,613 bytes |
| コンパイル時間 | 2,245 ms |
| コンパイル使用メモリ | 113,632 KB |
| 実行使用メモリ | 182,700 KB |
| 最終ジャッジ日時 | 2024-10-07 13:58:19 |
| 合計ジャッジ時間 | 7,993 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 10 RE * 6 TLE * 1 -- * 15 |
コンパイルメッセージ
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.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
int width = inpt[0];
int height = inpt[1];
int otona = inpt[2];
this.Road = new bool[width * height, width * height];
for(int i=0; i<otona; i++) {
int turnCount = int.Parse(Reader.ReadLine());
inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
if(inpt.Length > 1) {
for(int j=1;j<inpt.Length; j++) {
int pos1 = Math.Min(inpt[j-1], inpt[j]);
int pos2 = Math.Max(inpt[j-1], inpt[j]);
if(pos1 % width == pos2 % width) {
// 同じ列
for(int k=pos1; k<pos2; k+=width) {
this.Road[k, k+width] = true;
this.Road[k+width, k] = true;
}
} else
{
// 多分同じ行
for(int k=pos1; k<pos2; k++) {
this.Road[k, k+1] = true;
this.Road[k+1, k] = true;
}
}
}
}
}
int[] map = new int[width * height];
for(int i=0; i<width*height; i++) {
map[i] = int.MaxValue;
}
map[0] = 0;
Queue<int> taskQ = new Queue<int>();
taskQ.Enqueue(0);
while (taskQ.Count > 0)
{
int pos = taskQ.Dequeue();
int row = pos / width;
int col = pos % width;
int nextVal = map[pos] + 1;
int[][] nextPosList = new int[][] {new int[]{row + 1, col}, new int[] {row -1, col}, new int[]{row, col -1}, new int[]{row, col + 1}};
foreach (int[] nextPos in nextPosList)
{
if(nextPos[1] < 0 || nextPos[1] >= width || nextPos[0] < 0 || nextPos[0] >= height) {
continue;
}
int nPos = nextPos[0] * width + nextPos[1];
if(!this.Road[pos, nPos]) {
continue;
}
if(map[nPos] <= nextVal) {
continue;
}
map[nPos] = nextVal;
if(nPos == width * height - 1) {
continue;
}
taskQ.Enqueue(nPos);
}
}
int ans = map[width * height - 1];
if(ans == int.MaxValue) {
Console.WriteLine("Odekakedekinai..");
return;
}
Console.WriteLine(ans);
}
private bool[,] Road;
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
3 3 2
2
0 1 4
2
4 7 8
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番