結果

問題 No.707 書道
ユーザー m-44m-44
提出日時 2019-09-21 22:40:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 172,060 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 06:50:05
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
  int h, w;
  cin>>h>>w;
  string s[h];
  for (int i=0; i<h; i++) cin>>s[i];

  vector<pair<int, int> > ps;
  for (int i=1; i<=w; i++) {
    ps.push_back(make_pair(0, i));
    ps.push_back(make_pair(h+1, i));
  }
  for (int i=1; i<=h; i++) {
    ps.push_back(make_pair(i, 0));
    ps.push_back(make_pair(i, w+1));
  }

  double ans = 1e14;

  for (auto p: ps) {
    int y = p.first;
    int x = p.second;
    double tmp = 0.0;
    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        if (s[i][j] == '1') {
          tmp += sqrt(pow(y - i - 1, 2) + pow(x - j - 1, 2));
        }
      }
    }
    ans = min(tmp, ans);
  }
  printf("%.6lf\n", ans);
}
0