結果

問題 No.707 書道
ユーザー finefine
提出日時 2018-06-29 22:35:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 168,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:23:44
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

double calc(int x, int y, int H, int W, vector<string>& p) {
    double res = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (p[i][j] == '0') continue;
            int x2 = j + 1, y2 = i + 1;
            res += hypot((x - x2), (y - y2));
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> p(H);
    for (int i = 0; i < H; i++) {
        cin >> p[i];
    }

    double ans = 1e15;
    for (int i = 0; i < H; i++) {
        int y = i + 1;
        int x = 0;
        ans = min(ans, calc(x, y, H, W, p));
        x = W + 1;
        ans = min(ans, calc(x, y, H, W, p));
    }

    for (int j = 0; j < W; j++) {
        int x = j + 1;
        int y = 0;
        ans = min(ans, calc(x, y, H, W, p));
        y = H + 1;
        ans = min(ans, calc(x, y, H, W, p));
    }
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}
0