結果
問題 | No.86 TVザッピング(2) |
ユーザー |
![]() |
提出日時 | 2014-12-05 00:38:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,732 ms / 5,000 ms |
コード長 | 2,132 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 116,056 KB |
実行使用メモリ | 51,000 KB |
最終ジャッジ日時 | 2025-06-20 13:57:09 |
合計ジャッジ時間 | 6,140 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
コンパイルメッセージ
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; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ dx=new int[]{0,1,0,-1}; dy=new int[]{1,0,-1,0}; int Tot=0; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(S[i][j]=='.')Tot++; } } bool chk=false; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(S[i][j]=='#')continue; R0=i;C0=j; for(int dir=0;dir<4;dir++){ map=new bool[N*M]; int ret=dfs(i,j,dir); //Console.WriteLine(ret); if(Tot==ret){ chk=true; break; } } if(chk)break; } if(chk)break; } Console.WriteLine(chk?"YES":"NO"); } int R0,C0; int dfs(int r,int c,int d){ //Console.WriteLine("r={0},c={1},d={2}",r,c,d); int ret=1; map[r*M+c]=true; int nr=r+dy[d]; int nc=c+dx[d]; bool last=false; if(nr==R0&&nc==C0)last=true; if(nr>=0&&nr<N&&nc>=0&&nc<M&&S[nr][nc]=='.'&&map[nr*M+nc]==false){ ret+=dfs(nr,nc,d); }else{ d++; d%=4; nr=r+dy[d]; nc=c+dx[d]; if(nr==R0&&nc==C0)last=true; if(nr>=0&&nr<N&&nc>=0&&nc<M&&S[nr][nc]=='.'&&map[nr*M+nc]==false){ ret+=dfs(nr,nc,d); } } if(ret==1 && last==false){ ret=-20000; } return ret; } bool[] map; int[] dx; int[] dy; int N,M; String[] S; public Sol(){ var d=ria(); N=d[0];M=d[1]; S=new String[N]; for(int i=0;i<N;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(){return Console.ReadLine().Split(' ');} static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));} static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));} static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));} }