結果

問題 No.707 書道
ユーザー bal4ubal4u
提出日時 2019-06-25 18:45:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 30,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 08:48:43
合計ジャッジ時間 838 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// 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