結果
問題 |
No.707 書道
|
ユーザー |
![]() |
提出日時 | 2018-07-26 13:31:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 853 bytes |
コンパイル時間 | 1,713 ms |
コンパイル使用メモリ | 170,932 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 03:17:10 |
合計ジャッジ時間 | 2,141 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#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; }