結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 2018-08-13 15:01:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 696 bytes |
コンパイル時間 | 672 ms |
コンパイル使用メモリ | 69,472 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-09-24 08:01:17 |
合計ジャッジ時間 | 1,076 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#include<iostream>#include<cmath>#include<cstdio>using ll = long long;using namespace std;string p[51];double h,w,x,y;double calc(){double sum=0;for(int i=1;i<=h;i++){for(int j=0;j<w;j++){if(p[i][j]=='1') sum+=sqrt(double((x-j-1)*(x-j-1)+(y-i)*(y-i)));}}return sum;}int main(){double ans=1000000;cin >> h >> w;for(int i=1;i<=h;i++) cin >> p[i];x=0;for(y=1;y<=h;y++) ans = min(calc(),ans);x=w+1;for(y=1;y<=h;y++) ans = min(calc(),ans);y=0;for(x=1;x<=w;x++) ans = min(calc(),ans);y=h+1;for(x=1;x<=w;x++) ans = min(calc(),ans);printf("%f\n",ans);return 0;}