結果

問題 No.707 書道
ユーザー nominomi
提出日時 2018-06-30 08:20:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 164,208 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 16:11:41
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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