結果

問題 No.707 書道
ユーザー potoooooooopotoooooooo
提出日時 2018-06-29 22:48:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 170,912 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:30:04
合計ジャッジ時間 2,182 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0