結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2018-06-29 23:45:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,663 bytes |
コンパイル時間 | 895 ms |
コンパイル使用メモリ | 113,564 KB |
実行使用メモリ | 28,528 KB |
最終ジャッジ日時 | 2024-07-01 00:24:50 |
合計ジャッジ時間 | 1,810 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
コンパイルメッセージ
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.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);}}}