結果
問題 | No.707 書道 |
ユーザー |
|
提出日時 | 2018-07-06 10:51:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 74,948 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 02:43:45 |
合計ジャッジ時間 | 1,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#include<iostream>#include<cfloat>#include<cmath>#include<iomanip>using namespace std;char mat[52][52];int h, w;double solve(int x, int y){double dist = 0;for(int i = 1; i <= h; i++){for(int j = 1; j <= w; j++){if(mat[i][j] == '1'){dist += sqrt(pow(x-i, 2.0) + pow(y-j, 2.0));}}}return dist;}int main(){cin >> h >> w;for(int i = 1; i <= h; i++){for(int j = 1; j <= w; j++){cin >> mat[i][j];}}double ans = DBL_MAX;for(int i = 1; i <= w; i++){ans = min(ans, solve(0, i));ans = min(ans, solve(h+1, i));}for(int i = 1; i <= h; i++){ans = min(ans, solve(i,0));ans = min(ans, solve(i,w+1));}cout << fixed << setprecision(7) << ans << endl;return 0;}