結果

問題 No.707 書道
ユーザー 👑 tatyamtatyam
提出日時 2018-06-29 23:06:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 145,872 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:36:05
合計ジャッジ時間 1,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)
int h,w;
double paint(int a,int b,array<array<bool,51>,51> p){
    double ans=0;
    rep(i,1,h+1)rep(j,1,w+1)if(p[i][j])ans+=sqrt((a-i)*(a-i)+(b-j)*(b-j));
    return ans;
}
int main(){
    cin>>h>>w;
    array<array<bool,51>,51> p;
    string s;
    rep(i,1,h+1){
        cin>>s;
        rep(j,1,w+1)p[i][j]=s[j-1]-'0';
    }
    double mn=1e20,sum;
    rep(i,1,h+1){
        sum=paint(i,0,p);
        if(sum<mn)mn=sum;
    }
    rep(i,1,h+1){
        sum=paint(i,w+1,p);
        if(sum<mn)mn=sum;
    }
    rep(i,1,w+1){
        sum=paint(0,i,p);
        if(sum<mn)mn=sum;
    }
    rep(i,1,w+1){
        sum=paint(h+1,i,p);
        if(sum<mn)mn=sum;
    }
    fcout<<mn;
}
0