結果

問題 No.707 書道
ユーザー kametarokametaro
提出日時 2018-07-02 19:28:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 63,876 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 17:00:30
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 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,376 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <climits>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    // scanf("%d",&h);
    // scanf("%d",&w);
    char paper[52][52]={};
    // string asas;
    // getline(&asas);
    getchar();
    // getchar();
    // getchar();
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            //cin>>paper[j][i];
            paper[j][i]=getchar();
            // scanf("%c",paper[j][i]);
            // printf("-%c-",paper[j][i]);
        }
        getchar();
    }
    double tem,ans=999999999999.9;

    for(int k=1;k<=w;k++){
        tem=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(paper[j][i]!='0'){
                    tem+=sqrt((k-j)*(k-j)+(i-0)*(i-0));
                }
            }
        }
        ans=min(ans,tem);
    }
    for(int k=1;k<=w;k++){
        tem=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(paper[j][i]!='0'){
                    tem+=sqrt((k-j)*(k-j)+(i-(h+1))*(i-(h+1)));
                }
            }
        }
        ans=min(ans,tem);
    }
    for(int k=0;k<=w;k++){
        tem=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(paper[j][i]!='0'){
                    tem+=sqrt((0-j)*(0-j)+(i-k)*(i-k));
                }
            }
        }
        ans=min(ans,tem);
    }
    for(int k=0;k<=w;k++){
        tem=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(paper[j][i]!='0'){
                    tem+=sqrt(((w+1)-j)*((w+1)-j)+(i-k)*(i-k));
                }
            }
        }
        ans=min(ans,tem);
    }

    // cout<<ans<<endl;;
    printf("%f",ans);
    return 0;
}
0