結果
| 問題 | No.707 書道 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-06-30 22:40:10 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,018 bytes | 
| コンパイル時間 | 711 ms | 
| コンパイル使用メモリ | 75,412 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 01:02:18 | 
| 合計ジャッジ時間 | 1,197 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 | 
ソースコード
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
double GetDist(int x,int y,vector<pair<int,int>> &myV)
{
	int i;
	double dist=0;
	for (i=0;i<myV.size();i++){
		int x1=myV[i].first;
		int y1=myV[i].second;
		dist+=sqrt((double)(x-x1)*(x-x1)+(y-y1)*(y-y1));
	}
	return dist;
}
int main(int argc, char* argv[])
{
	int H,W;
	cin>>H>>W;
	vector<pair<int,int>> myV;
	int i,j;
	for (i=1;i<=H;i++){
		string S;
		cin>>S;
		for (j=0;j<S.size();j++){
			if (S[j]=='1'){
				myV.push_back(make_pair(j+1,i));
			}
		}
	}
	double dist;
	double MaxDist=1e9;
	for (j=1;j<=H;j++){
		dist=GetDist(0,j,myV);
		if (MaxDist>dist){
			MaxDist=dist;
		}
	}
	for (j=1;j<=H;j++){
		dist=GetDist(W+1,j,myV);
		if (MaxDist>dist){
			MaxDist=dist;
		}
	}
	for (i=1;i<=W;i++){
		dist=GetDist(i,0,myV);
		if (MaxDist>dist){
			MaxDist=dist;
		}
	}
	for (i=1;i<=W;i++){
		dist=GetDist(i,H+1,myV);
		if (MaxDist>dist){
			MaxDist=dist;
		}
	}
	printf("%.8lf\n",MaxDist);
	return 0;
}
            
            
            
        