結果

問題 No.707 書道
コンテスト
ユーザー nomi
提出日時 2018-06-30 08:20:55
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 808 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,446 ms
コンパイル使用メモリ 184,632 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-21 15:50:03
合計ジャッジ時間 1,522 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int H, W;
int B[111][111];

double calc(int x, int y) {
   double ret = 0;
   for (int yi = 1; yi <= H; yi++) {
      for (int xi = 1; xi <= W; xi++) {
         if (B[yi][xi]) ret += hypot(y - yi, x - xi);
      }
   }
   return ret;
}

int main() {
   cin >> H >> W;
   for (int yi = 0; yi < H; yi++) {
      string s; cin >> s;
      for (int xi = 0; xi < W; xi++) {
         B[yi+1][xi+1] = s[xi] - '0';
      }
   }

   double ans = 1e8;
   for (int yi = 1; yi <= H; yi++) { ans = min(ans, calc(0, yi)); }
   for (int yi = 1; yi <= H; yi++) { ans = min(ans, calc(W+1, yi)); }
   for (int xi = 1; xi <= W; xi++) { ans = min(ans, calc(xi, 0)); }
   for (int xi = 1; xi <= W; xi++) { ans = min(ans, calc(xi, H+1)); }

   printf("%.10f\n", ans);

   return 0;
}
0