結果

問題 No.707 書道
ユーザー face4face4
提出日時 2018-07-06 10:51:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 18:04:55
合計ジャッジ時間 1,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cfloat>
#include<cmath>
#include<iomanip>
using namespace std;

char mat[52][52];
int h, w;

double solve(int x, int y){
    double dist = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(mat[i][j] == '1'){
                dist += sqrt(pow(x-i, 2.0) + pow(y-j, 2.0));
            }
        }
    }
    return dist;
}

int main(){
    cin >> h >> w;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> mat[i][j];
        }
    }

    double ans = DBL_MAX;

    for(int i = 1; i <= w; i++){
        ans = min(ans, solve(0, i));
        ans = min(ans, solve(h+1, i));
    }

    for(int i = 1; i <= h; i++){
        ans = min(ans, solve(i,0));
        ans = min(ans, solve(i,w+1));
    }

    cout << fixed << setprecision(7) << ans << endl;

    return 0;
}
0