結果
問題 | No.1323 うしらずSwap |
ユーザー | fgwiebfaoish |
提出日時 | 2020-12-20 01:34:55 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,321 bytes |
コンパイル時間 | 3,983 ms |
コンパイル使用メモリ | 108,800 KB |
実行使用メモリ | 48,384 KB |
最終ジャッジ日時 | 2024-09-21 11:15:07 |
合計ジャッジ時間 | 29,644 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
17,920 KB |
testcase_01 | AC | 24 ms
18,048 KB |
testcase_02 | AC | 24 ms
17,920 KB |
testcase_03 | AC | 24 ms
18,176 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 24 ms
18,048 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 26 ms
18,048 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 25 ms
18,048 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 439 ms
48,000 KB |
testcase_17 | AC | 509 ms
40,960 KB |
testcase_18 | AC | 454 ms
48,000 KB |
testcase_19 | AC | 530 ms
41,088 KB |
testcase_20 | AC | 457 ms
48,000 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 449 ms
47,872 KB |
testcase_27 | AC | 449 ms
48,128 KB |
testcase_28 | AC | 516 ms
48,128 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 876 ms
41,088 KB |
testcase_34 | AC | 998 ms
48,384 KB |
testcase_35 | AC | 1,043 ms
41,216 KB |
testcase_36 | AC | 1,075 ms
48,256 KB |
testcase_37 | AC | 1,094 ms
41,088 KB |
testcase_38 | AC | 1,196 ms
41,216 KB |
testcase_39 | AC | 1,253 ms
48,128 KB |
testcase_40 | AC | 1,224 ms
41,216 KB |
testcase_41 | AC | 1,306 ms
48,256 KB |
testcase_42 | AC | 1,215 ms
41,216 KB |
testcase_43 | AC | 241 ms
48,128 KB |
testcase_44 | AC | 304 ms
40,832 KB |
testcase_45 | AC | 375 ms
48,128 KB |
testcase_46 | AC | 307 ms
41,216 KB |
testcase_47 | AC | 282 ms
48,256 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 | 28 ms
19,840 KB |
testcase_60 | AC | 28 ms
19,328 KB |
testcase_61 | WA | - |
コンパイルメッセージ
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.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;} }