結果
問題 |
No.707 書道
|
ユーザー |
|
提出日時 | 2018-07-09 21:48:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 868 ms |
コンパイル使用メモリ | 97,360 KB |
最終ジャッジ日時 | 2025-01-06 11:52:10 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#include <iostream> #include <vector> #include <array> #include <string> #include <iomanip> #include <cfloat> #include <cmath> using namespace std; double distance(int x1, int y1, int x2, int y2) { return sqrt(static_cast<double>((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))); } int main() { int H, W; cin >> H >> W; // ポイントを作成 vector<array<int, 2>> pts; for (int y = 1; y <= H; ++y) { string str; cin >> str; for (int x = 1; x <= W; ++x) { if (str.at(x - 1) == '1') pts.push_back({ x, y }); } } double minv = LDBL_MAX; for (int x = 1; x <= W; ++x) { double v1 = 0; double v2 = 0; for (const auto &pt : pts) { v1 += distance(x, 0, pt.at(0), pt.at(1)); v2 += distance(x, H + 1, pt.at(0), pt.at(1)); } minv = min(minv, v1); minv = min(minv, v2); } for (int y = 1; y <= H; ++y) { double v1 = 0; double v2 = 0; for (const auto &pt : pts) { v1 += distance(0, y, pt.at(0), pt.at(1)); v2 += distance(W + 1, y, pt.at(0), pt.at(1)); } minv = min(minv, v1); minv = min(minv, v2); } cout << fixed << setprecision(9) << minv << endl; return 0; }