結果

問題 No.1323 うしらずSwap
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-12-20 01:34:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,321 bytes
コンパイル時間 5,748 ms
コンパイル使用メモリ 114,004 KB
実行使用メモリ 54,604 KB
最終ジャッジ日時 2023-10-21 10:08:53
合計ジャッジ時間 33,860 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,272 KB
testcase_01 AC 29 ms
24,276 KB
testcase_02 AC 29 ms
24,272 KB
testcase_03 AC 29 ms
24,276 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 29 ms
24,272 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 28 ms
24,272 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 29 ms
24,276 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 532 ms
54,296 KB
testcase_17 AC 632 ms
47,208 KB
testcase_18 AC 524 ms
54,328 KB
testcase_19 AC 620 ms
47,236 KB
testcase_20 AC 508 ms
54,284 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 511 ms
54,324 KB
testcase_27 AC 513 ms
54,312 KB
testcase_28 AC 605 ms
54,328 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1,047 ms
47,420 KB
testcase_34 AC 1,150 ms
54,484 KB
testcase_35 AC 1,226 ms
47,456 KB
testcase_36 AC 1,274 ms
54,604 KB
testcase_37 AC 1,319 ms
47,492 KB
testcase_38 AC 1,415 ms
47,472 KB
testcase_39 AC 1,486 ms
54,496 KB
testcase_40 AC 1,480 ms
47,508 KB
testcase_41 AC 1,516 ms
54,604 KB
testcase_42 AC 1,444 ms
47,492 KB
testcase_43 AC 275 ms
54,296 KB
testcase_44 AC 359 ms
47,208 KB
testcase_45 AC 435 ms
54,356 KB
testcase_46 AC 357 ms
47,208 KB
testcase_47 AC 326 ms
54,296 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 31 ms
24,348 KB
testcase_60 AC 31 ms
24,280 KB
testcase_61 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
//using nint=System.Int32;
static class Program{
	const int mod=(int)1e9+7;
	static readonly int[][] di1=new int[][]{new int[]{-1,0},new int[]{1,0},new int[]{0,-1},new int[]{0,1}};
	static readonly int[][] di2=new int[][]{new int[]{-1,-1},new int[]{-1,0},new int[]{-1,1},new int[]{0,-1},new int[]{0,1},new int[]{1,-1},new int[]{1,0},new int[]{1,1}};
	static char[][] bm;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int h=s[0],w=s[1];
		char c='#';
		bm=new char[h+2][];
		var b1=new int[h+2][];
		var b2=new int[h+2][];
		var qu=new Queue<ValueTuple<int,int,int>>();
		for(int i = 1;i<=h;i++) {
			bm[i]=(c+sc.S+c).ToCharArray();
			b1[i]=new int[w+2];
			b2[i]=new int[w+2];
		}
		bm[0]=bm[h+1]=new string(c,w+2).ToCharArray();
		b1[0]=b1[h+1]=b2[0]=b2[h+1]=new int[w+2];

		qu.Enqueue(ValueTuple.Create(s[2],s[3],1));
		b1[s[2]][s[3]]=1;
		while(qu.Count>0){
			var e=qu.Dequeue();
			Fdi(e.Item1,e.Item2,(y,x)=>{
				if(bm[y][x]=='.'&&b1[y][x]==0){
					qu.Enqueue(ValueTuple.Create(y,x,e.Item3+1));
					b1[y][x]=e.Item3+1;
				}
			});
		}
		qu=new Queue<ValueTuple<int,int,int>>();
		qu.Enqueue(ValueTuple.Create(s[4],s[5],1));
		b2[s[4]][s[5]]=1;
		while(qu.Count>0){
			var e=qu.Dequeue();
			Fdi(e.Item1,e.Item2,(y,x)=>{
				if(bm[y][x]=='.'&&b2[y][x]==0){
					qu.Enqueue(ValueTuple.Create(y,x,e.Item3+1));
					b2[y][x]=e.Item3+1;
				}
			});
		}
		int ans=mod;
		for(int i = 1;i<=h;i++) {
			for(int j = 1;j<=w;j++) {
				if(bm[i][j]!=c){
					int p1=0,p2=0;
					var li1=new List<int>();
					var li2=new List<int>();
					Fdi(i,j,(y,x)=>{
						if(bm[y][x]!=c){
							if(b1[i][j]>b1[y][x]){p1++;}
							else{li1.Add(b2[y][x]);}
							if(b2[i][j]>b2[y][x]){p2++;}
							else{li2.Add(b1[y][x]);}
						}
					});
					if(p1+li1.Count>=3){ans=Min(ans,(b1[s[4]][s[5]]-1)*2+2);}
					if(p1>=2&&li1.Count>=1){
						li1.Sort();
						ans=Min(ans,(b1[i][j]-1)*2+li1[0]*2);
					}
					if(p2>=2&&li2.Count>=1){
						li2.Sort();
						ans=Min(ans,(b2[i][j]-1)*2+li2[0]*2);
					}
					if(i==s[2]&&j==s[3]&&p2>=2){ans=Min(ans,(b2[i][j]-1)*2);}
					if(i==s[4]&&j==s[5]&&p1>=2){ans=Min(ans,(b1[i][j]-1)*2);}
				}
			}
		}
		Console.WriteLine("{0}",ans==mod?-1:ans);
	}
	static void Fdi(int y,int x,Action<int,int> f){for(int i=0;i<4;i++){f(y+di1[i][0],x+di1[i][1]);}}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0