結果

問題 No.707 書道
ユーザー kyawashellkyawashell
提出日時 2018-06-29 22:42:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:27:16
合計ジャッジ時間 1,343 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

ll h,w;
char in[100][100];
bool p[100][100];

int main() {
    cin >> h >> w;
    rep(i,h)cin >> in[i];
    rep(i,h)rep(j,w) p[i][j] = in[i][j] - '0';

    double ans = 1e9;
    rep(x1,h+2)rep(y1,w+2) {
        double sum = 0;
        ll cou = 0;
        if(x1 == 0)cou++;
        if(x1 == h+1)cou++;
        if(y1 == 0)cou++;
        if(y1 == w+1)cou++;
        if(cou != 1)continue;
        for(int x2 = 1;x2 < h+1;x2++) {
            for(int y2 = 1;y2 < w+1;y2++) {
                if(p[x2 -1][y2-1])sum += sqrt(pow(x1-x2,2) + pow(y1-y2,2));
            }
        }
        ans = min(ans,sum);
    }
    printf("%.10f\n",ans);
    return 0;
}
0