結果

問題 No.707 書道
ユーザー バカらっくバカらっく
提出日時 2018-07-01 11:43:13
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,143 bytes
コンパイル時間 4,151 ms
コンパイル使用メモリ 110,136 KB
実行使用メモリ 26,212 KB
最終ジャッジ日時 2023-09-13 16:33:12
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
24,032 KB
testcase_01 AC 70 ms
26,040 KB
testcase_02 AC 76 ms
26,056 KB
testcase_03 WA -
testcase_04 AC 66 ms
21,932 KB
testcase_05 AC 86 ms
24,172 KB
testcase_06 AC 94 ms
24,120 KB
testcase_07 AC 104 ms
26,008 KB
testcase_08 AC 70 ms
26,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int h = inpt[0];
        int w = inpt[1];

        bool[,] map = new bool[h, w];

        for (int i = 0; i < h; i++) {
            bool[] row = Reader.ReadLine().Select(a => a == '1').ToArray();
            for (int j = 0; j < row.Length; j++) {
                map[i, j] = row[j];
            }
        }

        for (int i = 0; i < w; i++) {
            this.Min = Math.Min(this.Min, GetCost(0, i, map));    
            this.Min = Math.Min(this.Min, GetCost(h + 1, i, map));    
        }
        for (int i = 0; i < h; i++) {
            this.Min = Math.Min(this.Min, GetCost(i, 0, map));
            this.Min = Math.Min(this.Min, GetCost(i, w + 1, map));            
        }
        Console.WriteLine(this.Min);

    }


    private double Min = double.MaxValue;
    private double GetCost(int h, int w, bool[,] map) {
        double ret = 0;
        for (int i = 0; i < map.GetLength(0); i++) {
            for (int j = 0; j < map.GetLength(1); j++) {
                if(!map[i,j]) {
                    continue;
                }
                ret += Math.Sqrt(Math.Pow(Math.Abs(h - (i + 1)), 2) + Math.Pow(Math.Abs(w - (j + 1)), 2));
                if(ret > Min) {
                    break;
                }
            }
            if(ret > this.Min) {
                break;
            }
        }
        return ret;
    }


    public class Reader
    {
        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 = @"



30 27
101111001101011000001011000
111100011101011110100101010
010001110101011101010100101
000001101000010000110001110
100010011101011111111110110
101100101110001010101011110
001010000010111110011011010
111110011010011100000001110
010101010011001000111001001
100001011100100000100000100
000110011110100111101110010
000000001101010001100010110
111110110110100000010100000
011010001000011100100111001
001011110110010000010001000
000101110001001000110111110
010010110001000100000111100
101101110101101101111100111
100110100011001001111101011
000010010000000000100101011
110001000101101101100000010
011111011101111101011010010
011110011111001110000111110
111111000011000110000010001
110001111011100001110110111
010101000101001011001110101
000101111110110010110000111
111011001101110101101100100
100011000100100011001010100
100010000100110100001111110




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0