結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2018-07-01 01:58:50 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 85,944 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 01:03:57 |
合計ジャッジ時間 | 1,174 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:58:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 58 | scanf("%d%d", &h, &w); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:62:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 707.cc: No.707 書道 - yukicoder*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<deque>#include<algorithm>#include<numeric>#include<utility>#include<complex>#include<functional>using namespace std;/* constant */const int MAX_H = 50;const int MAX_W = 50;const int MAX_N = MAX_H * MAX_W;const double DINF = 1.0e60;/* typedef *//* global variables */char s[MAX_W + 2];int xs[MAX_N], ys[MAX_N];/* subroutines */double dsum(int n, int x0, int y0) {double sum = 0.0;for (int i = 0; i < n; i++) {int dx = x0 - xs[i], dy = y0 - ys[i];sum += sqrt(dx * dx + dy * dy);}return sum;}inline void setmin(double &a, double b) { if (a > b) a = b; }/* main */int main() {int h, w;scanf("%d%d", &h, &w);int n = 0;for (int y = 1; y <= h; y++) {scanf("%s", s);for (int x = 1; x <= w; x++)if (s[x - 1] == '1') xs[n] = x, ys[n] = y, n++;}//printf("n=%d\n", n);double mind = DINF;for (int x = 1; x <= w; x++) {setmin(mind, dsum(n, x, 0));setmin(mind, dsum(n, x, h + 1));}for (int y = 1; y <= h; y++) {setmin(mind, dsum(n, 0, y));setmin(mind, dsum(n, w + 1, y));}printf("%.8lf\n", mind);return 0;}