結果

問題 No.707 書道
ユーザー neko_the_shadowneko_the_shadow
提出日時 2018-06-29 23:45:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 106,016 KB
実行使用メモリ 26,072 KB
最終ジャッジ日時 2023-09-13 15:49:01
合計ジャッジ時間 3,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
25,868 KB
testcase_01 AC 72 ms
23,888 KB
testcase_02 AC 73 ms
23,772 KB
testcase_03 AC 72 ms
25,916 KB
testcase_04 AC 69 ms
21,948 KB
testcase_05 AC 76 ms
23,824 KB
testcase_06 AC 81 ms
24,004 KB
testcase_07 AC 82 ms
23,988 KB
testcase_08 AC 72 ms
26,072 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.Collections.Generic;
using System.Linq;

namespace _707
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var h = line[0];
            var w = line[1];

            var blacks = new List<Tuple<int, int>>();
            for (int x = 0; x < h; x++)
            {
                var row = Console.ReadLine().Select(ch => ch - '0').ToList();
                for (int y = 0; y < w; y++)
                {
                    if (row[y] == 1)
                    {
                        blacks.Add(Tuple.Create(x + 1, y + 1));
                    }
                }
            }

            var positions = new List<Tuple<int, int>>();
            for (int x = 0; x <= h + 1; x++)
            {
                for (int y = 0; y <= w + 1; y++)
                {
                    if (x == 0 || x == h + 1 || y == 0 || y == w + 1)
                    {
                        positions.Add(Tuple.Create(x, y));
                    }
                }
            }

            var answer = double.MaxValue;
            foreach (var position in positions)
            {
                var sum = 0.0;
                foreach (var black in blacks)
                {
                    var x = Math.Pow((double)(position.Item1 - black.Item1), 2.0);
                    var y = Math.Pow((double)(position.Item2 - black.Item2), 2.0);
                    sum += Math.Sqrt(x + y);
                }

                answer = Math.Min(answer, sum);
            }

            Console.WriteLine(answer);
        }
    }
}
0