結果

問題 No.707 書道
ユーザー beetbeet
提出日時 2018-07-26 13:31:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 167,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 18:38:54
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];
  auto calc=
    [&](Int y,Int x){
      double res=0;
      for(Int i=0;i<h;i++)
	for(Int j=0;j<w;j++)
	  if(s[i][j]=='1') res+=hypot<double>(y-i,x-j);
      return res;
    };  
  double ans=calc(-1,0);
  for(Int i=0;i<h;i++) chmin(ans,calc(i,-1));
  for(Int i=0;i<h;i++) chmin(ans,calc(i,w));
  for(Int i=0;i<w;i++) chmin(ans,calc(-1,i));
  for(Int i=0;i<w;i++) chmin(ans,calc(h,i));
  cout<<ans<<endl;
  return 0;
}
0