結果
問題 | No.340 雪の足跡 |
ユーザー | eitaho |
提出日時 | 2016-03-23 05:23:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,194 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 118,768 KB |
実行使用メモリ | 55,344 KB |
最終ジャッジ日時 | 2024-10-01 19:27:02 |
合計ジャッジ時間 | 10,192 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
19,200 KB |
testcase_01 | AC | 31 ms
19,200 KB |
testcase_02 | AC | 30 ms
19,328 KB |
testcase_03 | AC | 31 ms
19,328 KB |
testcase_04 | AC | 32 ms
19,200 KB |
testcase_05 | WA | - |
testcase_06 | AC | 29 ms
19,328 KB |
testcase_07 | AC | 30 ms
19,328 KB |
testcase_08 | AC | 27 ms
19,200 KB |
testcase_09 | AC | 26 ms
19,200 KB |
testcase_10 | AC | 27 ms
19,328 KB |
testcase_11 | AC | 33 ms
20,096 KB |
testcase_12 | AC | 31 ms
19,968 KB |
testcase_13 | AC | 32 ms
20,096 KB |
testcase_14 | AC | 54 ms
23,776 KB |
testcase_15 | AC | 59 ms
24,064 KB |
testcase_16 | AC | 48 ms
23,848 KB |
testcase_17 | AC | 64 ms
24,064 KB |
testcase_18 | AC | 59 ms
24,192 KB |
testcase_19 | AC | 64 ms
24,192 KB |
testcase_20 | AC | 376 ms
47,656 KB |
testcase_21 | AC | 301 ms
43,896 KB |
testcase_22 | AC | 39 ms
22,784 KB |
testcase_23 | WA | - |
testcase_24 | AC | 355 ms
45,120 KB |
testcase_25 | AC | 400 ms
45,044 KB |
testcase_26 | AC | 98 ms
34,432 KB |
testcase_27 | AC | 43 ms
22,272 KB |
testcase_28 | AC | 78 ms
30,336 KB |
testcase_29 | AC | 414 ms
48,000 KB |
testcase_30 | AC | 265 ms
42,368 KB |
testcase_31 | AC | 437 ms
47,836 KB |
testcase_32 | AC | 508 ms
45,036 KB |
testcase_33 | AC | 385 ms
41,856 KB |
testcase_34 | AC | 505 ms
44,684 KB |
testcase_35 | AC | 498 ms
53,196 KB |
testcase_36 | AC | 503 ms
53,356 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { static readonly int INF = (int)1e9; static readonly string Impossible = "Odekakedekinai.."; static readonly int[] DR = { 0, 1, 0, -1 }; static readonly int[] DC = { 1, 0, -1, 0 }; public void Solve() { int W = Reader.Int(), H = Reader.Int(), N = Reader.Int(); var table = Reader.IntTable(N * 2); long[][] row = new long[H][]; long[][] col = new long[W][]; for (int r = 0; r < H; r++) row[r] = new long[(W + 63) / 64]; for (int c = 0; c < W; c++) col[c] = new long[(H + 63) / 64]; for (int ti = 1; ti < N * 2; ti += 2) { var t = table[ti]; for (int i = 0; i + 1 < t.Length; i++) { int r = t[i] / W, c = t[i] % W; int nr = t[i + 1] / W, nc = t[i + 1] % W; if (Math.Sign(nr - r) != 0) BitArrayOr(col[c], Math.Min(r, nr), Math.Max(r, nr) + 1); else BitArrayOr(row[r], Math.Min(c, nc), Math.Max(c, nc) + 1); } } bool[, ,] G = new bool[H, W, 4]; for (int r = 0; r < H; r++) for (int c = 0; c + 1 < W; c++) if ((row[r][c / 64] >> c & 1) == 1 && (row[r][(c + 1) / 64] >> (c + 1) & 1) == 1) { G[r, c, 0] = true; G[r, c + 1, 2] = true; } for (int c = 0; c < W; c++) for (int r = 0; r + 1 < H; r++) if ((col[c][r / 64] >> r & 1) == 1 && (col[c][(r + 1) / 64] >> (r + 1) & 1) == 1) { G[r, c, 1] = true; G[r + 1, c, 3] = true; } int ans = BFS(G, H, W); Console.WriteLine(ans == INF ? Impossible : ans + ""); } // [L, R) static void BitArrayOr(long[] A, int L, int R) { if (L >= R) return; int Li = L >> 6; if (Li == (R - 1 >> 6)) { if (R - L == 64) A[Li] |= -1L; else A[Li] |= (1L << R - L) - 1 << L; return; } int Ri = R >> 6; if ((L & 63) == 0) A[Li] |= -1L; else A[Li] |= (1L << 64 - L) - 1 << L; for (int i = Li + 1; i < Ri; i++) A[i] = -1L; A[Ri] |= (1L << R) - 1; } private int BFS(bool[, ,] G, int H, int W) { var minCost = new int[H, W]; for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) minCost[r, c] = INF; minCost[0, 0] = 0; var que = new Queue<int>(); que.Enqueue(0); que.Enqueue(0); while (que.Count > 0) { int r = que.Dequeue(), c = que.Dequeue(); for (int d = 0; d < DR.Length; d++) if (G[r, c, d]) { int nr = r + DR[d], nc = c + DC[d]; int nextCost = minCost[r, c] + 1; if (nextCost < minCost[nr, nc]) { if (nr == H - 1 && nc == W - 1) return nextCost; minCost[nr, nc] = nextCost; que.Enqueue(nr); que.Enqueue(nc); } } } return INF; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }