結果

問題 No.707 書道
ユーザー EsireEsire
提出日時 2018-11-04 17:36:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 97,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 03:24:22
合計ジャッジ時間 1,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
./main.exe
*/

#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <climits>
//intの最大値: INT_MAX
//longの最大値: LONG_MAX
//long longの最大値: LLONG_MAX
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::less<T>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::greater<T>());
    return;
}

//------------------------------------------------------------------------------

int h, w;
vector<string> p;

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

	string t;
	for(int i = 0; i < h; i++){
		cin >> t;
		p.push_back(t);
	}

	double min = 1000000.0, tmp = 0.0;
	for(int i = 0; i <= h + 1; i++){
		for(int j = 0; j <= w + 1; j++){
			if(((i == 0) && (j != 0) && (j != w + 1)) || ((i == h + 1) && (j != 0) && (j != w + 1)) || ((j == 0) && (i != 0) && (i != h + 1)) || ((j == w + 1) && (i != 0) && (i != h + 1))){
				for(int i2 = 0; i2 < h; i2++){
					for(int j2 = 0; j2 < w; j2++){
						if(p[i2][j2] == '1'){
							tmp += sqrt((i2 + 1 - i) * (i2 + 1 - i) + (j2 + 1 - j) * (j2 + 1 - j));
						}
					}
				}

				if(tmp < min) min = tmp;
				tmp = 0;
			}
		}
	}

	cout << setprecision(16) << min << endl;

	return 0;
}
0