結果

問題 No.707 書道
ユーザー Mcpu3Mcpu3
提出日時 2018-08-22 16:33:30
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 31,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 20:19:58
合計ジャッジ時間 1,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <float.h>

int main(void)
{
    double m=DBL_MAX,t;
    int h,w,p[52][52],i,j,k;
    scanf("%d%d",&h,&w);
    for(i=1;i<=h;i++)for(j=1;j<=w;j++)scanf("%1d",&p[i][j]);
    for(i=1;i<=w;i++){
        t=0;
        for(j=1;j<=h;j++)for(k=1;k<=w;k++)if(p[j][k])t+=hypot(k-i,j);
        if(m>t)m=t;
    }
    for(i=1;i<=h;i++){
        t=0;
        for(j=1;j<=h;j++)for(k=1;k<=w;k++)if(p[j][k])t+=hypot(k-w-1,j-i);
        if(m>t)m=t;
    }
    for(i=1;i<=w;i++){
        t=0;
        for(j=1;j<=h;j++)for(k=1;k<=w;k++)if(p[j][k])t+=hypot(k-i,j-h-1);
        if(m>t)m=t;
    }
    for(i=1;i<=h;i++){
        t=0;
        for(j=1;j<=h;j++)for(k=1;k<=w;k++)if(p[j][k])t+=hypot(k,j-i);
        if(m>t)m=t;
    }
    printf("%.7f",m);
    return 0;
}
0