結果

問題 No.707 書道
ユーザー バカらっくバカらっく
提出日時 2018-07-01 11:45:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,318 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 108,452 KB
実行使用メモリ 25,976 KB
最終ジャッジ日時 2023-09-13 16:33:24
合計ジャッジ時間 3,760 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
24,124 KB
testcase_01 AC 67 ms
23,776 KB
testcase_02 AC 75 ms
24,124 KB
testcase_03 AC 68 ms
24,104 KB
testcase_04 AC 64 ms
23,884 KB
testcase_05 AC 84 ms
24,140 KB
testcase_06 AC 94 ms
24,004 KB
testcase_07 AC 104 ms
23,964 KB
testcase_08 AC 69 ms
25,976 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 + 1, map));    
            this.Min = Math.Min(this.Min, GetCost(h + 1, i + 1, map));    
        }
        for (int i = 0; i < h; i++) {
            this.Min = Math.Min(this.Min, GetCost(i + 1, 0, map));
            this.Min = Math.Min(this.Min, GetCost(i + 1, 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 = @"



1 1
1



";
    }

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