結果
問題 | No.707 書道 |
ユーザー |
|
提出日時 | 2020-05-05 03:49:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 568 bytes |
コンパイル時間 | 2,303 ms |
コンパイル使用メモリ | 195,460 KB |
最終ジャッジ日時 | 2025-01-10 06:37:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | int h,w; scanf("%d%d",&h,&w); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const double INF=1e77; int main(){ int h,w; scanf("%d%d",&h,&w); vector<string> B(h); rep(i,h) cin>>B[i]; auto calc=[&](int i,int j){ double res=0; rep(y,h) rep(x,w) if(B[y][x]=='1') res+=hypot(x+1-j,y+1-i); return res; }; double ans=INF; rep(i,h+2){ if(i!= 0 ) ans=min(ans,calc(i, 0 )); if(i!=h+1) ans=min(ans,calc(i,w+1)); } rep(j,w+2){ if(j!= 0 ) ans=min(ans,calc( 0 ,j)); if(j!=w+1) ans=min(ans,calc(h+1,j)); } printf("%.9f\n",ans); return 0; }