結果

問題 No.707 書道
ユーザー kakira9618kakira9618
提出日時 2018-06-29 22:31:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 86,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:22:07
合計ジャッジ時間 1,151 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<30;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

double calc(vector<string> &P, int y, int x) {
  double ret = 0.0;
  int H = P.size(), W = P[0].size();
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (P[i][j] == '1') {
        ret += sqrt((i + 1 - y) * (i + 1 - y) + (j + 1 - x) * (j + 1 - x));
      }
    }
  }
  return ret;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> P(H);
  for (int i = 0; i < H; i++) {
    cin >> P[i];
  }
  double ans = 1e20;
  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) {
        ans = min(ans, calc(P, i, j));
      }
    }
  }
  printf("%10.9f\n", ans);

  return 0;
}
0