結果

問題 No.707 書道
コンテスト
ユーザー bal4u
提出日時 2019-06-25 18:45:02
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,008 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 179 ms
コンパイル使用メモリ 42,220 KB
最終ジャッジ日時 2026-02-22 03:40:18
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: No.707 書道
// 2019.6.25 bal4u

#include <stdio.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	int c;
	while (1) {
		if ((c = gc()) < '0') break;
		*s++ = c & 1;
	}
}

int H, W;
char map[55][55];
double ans;

void calc(int r0, int c0) {
	int r, c;
	double s = 0;
	for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) if (map[r][c]) {
		s += hypot(r-r0, c-c0);
		if (s > ans) return;
	}
	ans = s;
}

int main()
{
	int r, c;

	H = in(), W = in();
	for (r = 1; r <= H; r++) ins(map[r]+1);
	ans = 1.0e20;
	r = 0;   for (c = 1; c <= W; c++) calc(r, c);
	r = H+1; for (c = 1; c <= W; c++) calc(r, c);
	c = 0;   for (r = 1; r <= H; r++) calc(r, c);
	c = W+1; for (r = 1; r <= H; r++) calc(r, c);
	printf("%.12lf\n", ans);
	return 0;
}
0