結果

問題 No.707 書道
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-08-15 18:16:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 98,964 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:28:43
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <float.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int H,W;
    cin >> H >> W;
    vector< vector<int> > P( H+2, vector<int>(W+2, 0) );

    for ( int i = 1; i <= H; i++ ) {
        string s;
        cin >> s;
        for ( int j = 1; j <= W; j++ ) {
            P[i][j] = s[j-1]-'0';
        }
    }

    double ans = DBL_MAX;
    for ( int i = 1; i <= W; i++ ) {
        
        double a,b;
        a = b = 0;

        for ( int y = 1; y <= H; y++ ) {
        for ( int x = 1; x <= W; x++ ) {

            if ( P[y][x] ) {
                a += sqrt( (x-i)*(x-i)+y*y );
                b += sqrt( (x-i)*(x-i)+(y-(H+1))*(y-(H+1)) );
            }
        }
        }

        ans = min( ans, min(a,b) );

    }

    for ( int i = 1; i <= H; i++ ) {
        
        double a,b;
        a = b = 0;

        for ( int y = 1; y <= H; y++ ) {
        for ( int x = 1; x <= W; x++ ) {
            if ( P[y][x] ) {
                a += sqrt( x*x+(y-i)*(y-i) );
                b += sqrt( (x-(W+1))*(x-(W+1))+(y-i)*(y-i) );
            }
        }
        }

        ans = min( ans, min(a,b) );

    }

    printf( "%.9f\n", ans );



    return 0;
}
0