結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-31 01:30:41 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 306 ms / 5,000 ms |
| コード長 | 3,252 bytes |
| コンパイル時間 | 2,772 ms |
| コンパイル使用メモリ | 112,628 KB |
| 実行使用メモリ | 23,140 KB |
| 最終ジャッジ日時 | 2024-10-13 10:51:00 |
| 合計ジャッジ時間 | 4,345 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
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;
// Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff"));
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");
// Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff"));
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});
}
log.Add(key);
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;
}
bool ret = this.GetAns(pos[0], pos[1], posX, posY, log);
if(ret) {
return true;
}
}
log.Remove(key);
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 = @"
";
}
14番