結果
| 問題 | No.707 書道 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-06-29 22:48:42 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 737 bytes | 
| コンパイル時間 | 1,778 ms | 
| コンパイル使用メモリ | 173,364 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 00:05:36 | 
| 合計ジャッジ時間 | 2,135 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int m[60][60];
vector<double> tmp;
void search(int x, int y, int h, int w) {
  double t = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (m[i][j] == 1) {
        t += sqrt((i-x)*(i-x)+(j-y)*(j-y));
      }
    }
  }
  tmp.push_back(t);
}
int main(){
  int h, w; cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s; cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '1') m[i+1][j+1]++;
    }
  }
  for (int i = 1; i <= h; i++) {
    search(i, 0, h, w); search(i, w+1, h, w);
  }
  for (int i = 1; i <= w; i++) {
    search(0, i, h, w); search(h+1, i, h, w);
  }
  sort(tmp.begin(), tmp.end());
  printf("%.9f\n", tmp[0]);
  return 0;
}
            
            
            
        