結果
| 問題 |
No.640 76本のトロンボーン
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2018-01-27 23:53:51 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,348 bytes |
| コンパイル時間 | 1,015 ms |
| コンパイル使用メモリ | 115,772 KB |
| 実行使用メモリ | 852,852 KB |
| 最終ジャッジ日時 | 2024-12-29 07:08:56 |
| 合計ジャッジ時間 | 17,774 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 1 |
| other | AC * 4 WA * 6 TLE * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc()
{
this.N = int.Parse(Reader.ReadLine());
bool[][] map = new bool[this.N][];
for (int i = 0; i < this.N; i++) {
map[i] = Reader.ReadLine().Select(a => a == '.').ToArray();
}
int ans = GetAns(0, map, GetKey(0, map));
Console.WriteLine(ans);
}
private Dictionary<string, int> dic = new Dictionary<string, int>();
private int GetAns(int idx, bool[][] map, string key) {
if(idx>=this.N*this.N) {
return 0;
}
int r = idx / this.N;
int c = idx % this.N;
if(!map[r][c]) {
return GetAns(idx + 1, map, key.Substring(1));
}
if(dic.ContainsKey(key)) {
return dic[key];
}
int ans = 0;
if(r+(this.N-1)<this.N) {
bool canSet = true;
for (int i = r; i < r + this.N - 1; i++) {
if(!map[i][c]) {
canSet = false;
break;
}
}
if(canSet) {
for (int i = r; i < r + this.N - 1; i++) {
map[i][c] = false;
}
string newKey = GetKey(idx + 1, map);
ans = Math.Max(ans, GetAns(idx + 1, map, newKey)+1);
for (int i = r; i < r + this.N - 1; i++)
{
map[i][c] = true;;
}
}
}
if(c+(this.N-1)<this.N) {
bool canSet = true;
for (int i = c; i < c + this.N - 1; i++) {
if(!map[r][i]) {
canSet = false;
break;
}
}
if (canSet)
{
for (int i = c; i < c + this.N - 1; i++)
{
map[r][i] = false;
}
string newKey = GetKey(idx + 1, map);
ans = Math.Max(ans, GetAns(idx + 1, map, newKey)+1);
for (int i = c; i < c + this.N - 1; i++)
{
map[r][i] = true;;
}
}
}
ans = Math.Max(ans, GetAns(idx + 1, map, key.Substring(1)));
dic[key] = ans;
return ans;
}
private string GetKey(int idx, bool[][] map) {
String ret = string.Join("", map.Select(a => string.Join("", a.Select(b => b ? "1" : "0"))));
return ret.Substring(idx);
}
private int N;
public class Reader
{
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine()
{
if (IsDebug)
{
if (sr == null)
{
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
private static string InputText = @"
5
#.#.#
.....
#.#.#
#.#.#
.....
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく