結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2016-09-22 22:55:46 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 2,363 bytes |
| コンパイル時間 | 899 ms |
| コンパイル使用メモリ | 114,304 KB |
| 実行使用メモリ | 26,276 KB |
| 最終ジャッジ日時 | 2024-07-05 07:05:02 |
| 合計ジャッジ時間 | 2,356 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
Func<int,int,bool> InRange = (r,c) =>{
return 0<=r && r<H && 0 <= c && c <W;
};
int[][] min = new int[H][];
for(int i=0;i<H;i++){
min[i] = new int[W];
for(int j=0;j<W;j++){
min[i][j] = -1;
}
}
int[] dy = new int[]{0,-1,0,1};
int[] dx = new int[]{1,0,-1,0};
int md = 1<<10;
Func<int,int,int> enc = (r,c)=> r*md + c;
Func<int,int,bool> canGo1 = (from,to) => {
return Math.Abs(S[from/md][from%md] - S[to/md][to%md])<=1;
};
Func<int,int,bool> canGo2 = (from,to) => {
return (S[from/md][from%md] == S[to/md][to%md]) && (S[from/md][from%md] > S[((from + to)/2)/md][((from + to)/2)%md]);
};
Queue<int> Q = new Queue<int>();
Q.Enqueue(enc(sy,sx));
min[sy][sx] = 0;
while(Q.Count>0){
var p = Q.Dequeue();
int r = p/md;
int c = p%md;
for(int t=0;t<4;t++){
int ny = r + dy[t];
int nx = c + dx[t];
if(InRange(ny,nx) && canGo1(p,enc(ny,nx)) && min[ny][nx] == -1){
min[ny][nx] = min[r][c] + 1;
Q.Enqueue(enc(ny,nx));
}
ny = r + 2*dy[t];
nx = c + 2*dx[t];
if(InRange(ny,nx) && canGo2(p,enc(ny,nx)) && min[ny][nx] == -1){
min[ny][nx] = min[r][c] + 1;
Q.Enqueue(enc(ny,nx));
}
}
}
Console.WriteLine(min[gy][gx] == -1?"NO":"YES");
}
int H,W;
int sx,sy,gx,gy;
String[] S;
public Sol(){
var d = ria();
H = d[0];
W = d[1];
d = ria();
sy = d[0]-1;
sx = d[1]-1;
gy = d[2]-1;
gx = d[3]-1;
S = new String[H];
for(int i=0;i<H;i++){
S[i] = rs();
}
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
kuuso1