結果

問題 No.707 書道
ユーザー KhiromuKhiromu
提出日時 2018-06-29 22:42:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,607 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 64,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:27:24
合計ジャッジ時間 1,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

int h, w;
string p[51];
int main() {
    cin>>h>>w;
    REP(i, 0, h) cin>>p[i];

    double ans=1000000007.0;
    REP(k, 1, w+1){
        double dist=0.0;
        REP(i, 0, h){
            REP(j, 0, w){
                if(p[i][j]=='1'){
                    dist+=sqrt((j+1-k)*(j+1-k)+(i+1)*(i+1));
                }
            }
        }
        ans=min(ans, dist);
    }
    REP(k, 1, h+1){
        double dist=0.0;
        REP(i, 0, h){
            REP(j, 0, w){
                if(p[i][j]=='1'){
                    dist+=sqrt((j+1)*(j+1)+(i+1-k)*(i+1-k));
                }
            }
        }
        ans=min(ans, dist);
    }
    REP(k, 1, h+1){
        double dist=0.0;
        REP(i, 0, h){
            REP(j, 0, w){
                if(p[i][j]=='1'){
                    dist+=sqrt((w+1-(j+1))*(w+1-(j+1))+(i+1-k)*(i+1-k));
                }
            }
        }
        ans=min(ans, dist);
    }
    REP(k, 1, w+1){
        double dist=0.0;
        REP(i, 0, h){
            REP(j, 0, w){
                if(p[i][j]=='1'){
                    dist+=sqrt((j+1-k)*(j+1-k)+(h+1-(i+1))*(h+1-(i+1)));
                }
            }
        }
        ans=min(ans, dist);
    }
    printf("%.10lf\n", ans);
    return 0;
}
0