結果
| 問題 |
No.707 書道
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-29 22:42:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,607 bytes |
| コンパイル時間 | 505 ms |
| コンパイル使用メモリ | 65,036 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 00:03:08 |
| 合計ジャッジ時間 | 995 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;
const int INF = 1e9 + 7;
const long long LLINF = 1e18;
int h, w;
string p[51];
int main() {
cin>>h>>w;
REP(i, 0, h) cin>>p[i];
double ans=1000000007.0;
REP(k, 1, w+1){
double dist=0.0;
REP(i, 0, h){
REP(j, 0, w){
if(p[i][j]=='1'){
dist+=sqrt((j+1-k)*(j+1-k)+(i+1)*(i+1));
}
}
}
ans=min(ans, dist);
}
REP(k, 1, h+1){
double dist=0.0;
REP(i, 0, h){
REP(j, 0, w){
if(p[i][j]=='1'){
dist+=sqrt((j+1)*(j+1)+(i+1-k)*(i+1-k));
}
}
}
ans=min(ans, dist);
}
REP(k, 1, h+1){
double dist=0.0;
REP(i, 0, h){
REP(j, 0, w){
if(p[i][j]=='1'){
dist+=sqrt((w+1-(j+1))*(w+1-(j+1))+(i+1-k)*(i+1-k));
}
}
}
ans=min(ans, dist);
}
REP(k, 1, w+1){
double dist=0.0;
REP(i, 0, h){
REP(j, 0, w){
if(p[i][j]=='1'){
dist+=sqrt((j+1-k)*(j+1-k)+(h+1-(i+1))*(h+1-(i+1)));
}
}
}
ans=min(ans, dist);
}
printf("%.10lf\n", ans);
return 0;
}