結果

問題 No.707 書道
ユーザー ajinoriajinori
提出日時 2018-06-29 23:09:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 165,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:36:50
合計ジャッジ時間 2,018 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const double inf = 900900900100.0;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    int h,w;
    cin >> h >> w;
    string s[55] = {};
    double madist = inf;
    rep(y,h) cin >> s[y];
    rep(y,h+2)rep(x,w+2){
        if(y==h+1&&x==w+1)   continue;
        if(y==0  &&x ==0)    continue;
        if(y==h+1&&x ==0)    continue;
        if(y==0  &&x ==w+1)  continue;

        if(x==0||y==0||x==w+1||y==h+1){
            double dist = 0.0;
            REP(yy,1,h+1)REP(xx,1,w+1){
                if(y==yy&&x==xx) continue;
                if(s[yy-1][xx-1]=='1'){
                    dist += sqrtl((double)(yy-y)*(yy-y)+(double)(xx-x)*(xx-x));
//                    cout << dist << endl;
                }
            }

//            cout << dist << endl;
            madist = min<double>(madist,dist);
        }

    }
    cout <<setprecision(9)<< madist << endl;

    return 0;
}
0