結果

問題 No.640 76本のトロンボーン
ユーザー バカらっくバカらっく
提出日時 2018-01-27 23:56:17
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,349 bytes
コンパイル時間 2,453 ms
コンパイル使用メモリ 108,616 KB
実行使用メモリ 210,280 KB
最終ジャッジ日時 2023-08-28 10:05:32
合計ジャッジ時間 6,738 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
26,140 KB
testcase_01 AC 67 ms
21,888 KB
testcase_02 AC 70 ms
21,896 KB
testcase_03 AC 68 ms
21,800 KB
testcase_04 AC 68 ms
21,888 KB
testcase_05 AC 67 ms
21,932 KB
testcase_06 AC 341 ms
83,644 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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-2)<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-2)<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();
    }
}
0