結果
| 問題 | No.13 囲みたい! |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-31 01:18:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,216 bytes |
| 記録 | |
| コンパイル時間 | 945 ms |
| コンパイル使用メモリ | 109,488 KB |
| 実行使用メモリ | 336,280 KB |
| 最終ジャッジ日時 | 2024-10-02 08:19:31 |
| 合計ジャッジ時間 | 7,697 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 12 |
コンパイルメッセージ
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.Text;
public class Program
{
public void Proc(){
Reader.IsDebug = false;
int[] inpt = Reader.GetInt();
this.Width = inpt[0];
this.Height = inpt[1];
this.map = new int[Height, Width];
this.flag = new bool[Height, Width];
for(int i=0; i<Height; i++) {
inpt = Reader.GetInt();
for(int j=0; j<inpt.Length; j++) {
this.map[i,j] = inpt[j];
}
}
for(int i=0; i<Height; i++) {
for(int j=0; j<Width; j++) {
if(!this.flag[i,j]) {
bool ret = this.GetAns(j,i,-1,-1,new List<String>());
if(ret) {
Console.WriteLine("possible");
return;
}
}
}
}
Console.WriteLine("impossible");
}
private int[,] map;
private bool[,] flag;
private bool GetAns(int posX, int posY, int prevX, int prevY, List<String> log) {
string key = posX + "#" + posY;
this.flag[posY, posX] = true;
List<int[]> nextPosList = new List<int[]>();
if(posX > 0) {
nextPosList.Add(new int[]{posX - 1, posY });
}
if(posX < Width - 1) {
nextPosList.Add(new int[]{posX + 1, posY });
}
if(posY > 0) {
nextPosList.Add(new int[]{posX, posY - 1});
}
if(posY < Height - 1) {
nextPosList.Add(new int[]{posX, posY + 1});
}
foreach (int[] pos in nextPosList)
{
if(pos[0] == prevX && pos[1] == prevY) {
continue;
}
if(this.map[pos[1], pos[0]] != this.map[posY, posX]) {
continue;
}
string nextKey = pos[0] + "#" + pos[1];
if(log.Contains(nextKey)) {
return true;
}
List<string> newLog = new List<string>();
newLog.AddRange(log);
newLog.Add(key);
bool ret = this.GetAns(pos[0], pos[1], posX, posY, newLog);
if(ret) {
return true;
}
}
return false;
}
private int Width;
private int Height;
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
class Reader
{
public static bool IsDebug = true;
private static System.IO.StringReader sr;
public static string ReadLine() {
if(IsDebug) {
if(sr == null) {
sr = new System.IO.StringReader(initStr.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ') {
string[] inpt = ReadLine().Split(delimiter);
int[] ret = new int[inpt.Length];
for(int i=0; i<inpt.Length; i++) {
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
private static string initStr = @"
5 4
5 5 5 3 5
5 3 1 5 1
5 2 2 5 8
5 5 5 5 9
";
}
14番