結果

問題 No.707 書道
ユーザー ama_nukoama_nuko
提出日時 2018-07-10 19:14:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 98,968 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 16:08:44
合計ジャッジ時間 1,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int h, w;
    cin >> h >> w;

    vector<vector<int>> p(h+1, vector<int>(w+1));
    rep(i, h) rep(j, w){
        char c;
        cin >> c;
        p[i+1][j+1] = c - '0';
    }

    double min = 1e15;
    for(int i = 0; i <= h+1; i++){
        for(int j = 0; j <= w+1; j++){
            if(i != 0 && i != h+1 && j != 0 && j != w+1){
                continue;
            }
            double tmp = 0;
            rep(k, h+1){
                rep(l, w+1){
                    if(p[k][l] == 0){
                        continue;
                    }
                    tmp += sqrt(pow(i-k, 2) + pow(j-l, 2));
                }
            }
            if(tmp < min){
                min = tmp;
            }
        }
    }
    cout << fixed << setprecision(6) << min << endl;

    return 0;
}
0