結果

問題 No.707 書道
ユーザー _shota_224__shota_224_
提出日時 2018-06-29 22:55:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,270 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 117,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:32:00
合計ジャッジ時間 1,648 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//#define int long long
#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define P(p) cout << (p) << endl;
#define S(s) cin << (s);
#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,n)
#define repst(i,a,b) rep(i,s,(n)+1)
#define rept(i,n) rep(i,(n)+1)
#define reprt(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define repr(i,n) reprt(i,n,0)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define debug(x) cerr << #x << ": " << x << '\n'
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

/*********TEMPLATE**********/

ld calc(int x1, int y1, int x2, int y2) {
  //cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) << ln;
  return sqrtl((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main() {

  int H, W;
  char c;
  string s;
  int board[50][50];
  cin >> H >> W;
  rep(i,H) {
    cin >> s;
    rep(j,W) {
      c = s[j];
      board[i][j] = c - '0';
    }
  }

  ld min = INF, tmp;
  // 左側
  rep(i,H) {
    tmp = 0;
    int x = i;
    int y = -1;
    rep(p,H) {
      rep(q,W) {
        if (board[p][q]==1)
          tmp += calc(p, q, x, y);
      }
    }//cout << x << ',' << y << ' ' << tmp << ln;
    if (min > tmp) min = tmp;
  }
  // 右側
  rep(i,H) {
    tmp = 0;
    int x = i;
    int y = W;
    rep(p,H) {
      rep(q,W) {
        if (board[p][q]==1)
          tmp += calc(p, q, x, y);
      }
    }//cout << x << ',' << y << ' ' << tmp << ln;
    if (min > tmp) min = tmp;
  }
  // 上側
  rep(i,W) {
    tmp = 0;
    int x = -1;
    int y = i;
    rep(p,H) {
      rep(q,W) {
        if (board[p][q]==1)
          tmp += calc(p, q, x, y);
      }
    }//cout << x << ',' << y << ' ' << tmp << ln;
    if (min > tmp) min = tmp;
  }
  // 下側
  rep(i,W) {
    tmp = 0;
    int x = H;
    int y = i;
    rep(p,H) {
      rep(q,W) {
        if (board[p][q]==1)
          tmp += calc(p, q, x, y);
      }
    }//cout << x << ',' << y << ' ' << tmp << ln;
    if (min > tmp) min = tmp;
  }

  cout << setprecision(100) << min << ln;
  /*
  rep(i,H) {
    rep(j,W) {
      cout << board[i][j] << ' ';
    }
    cout << ln;
  }
*/

  return 0;
}
0