結果

問題 No.707 書道
ユーザー gotutiyangotutiyan
提出日時 2018-06-30 01:23:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,149 bytes
コンパイル時間 985 ms
コンパイル使用メモリ 100,688 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 16:03:32
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    int h,w;
    cin>>h>>w;
    double ans=INF;

    vector<vector<char>> vv(h+2,vector<char>(w+2));
    vector<vector<int>> v(h+2,vector<int>(w+2,0));
    rep(i,0,h)rep(j,0,w){
        cin>>vv[i+1][j+1];
        v[i+1][j+1]=vv[i+1][j+1]-'0';
    }

    rep(i,1,h+1){
        double diff=0;
        rep(j,1,h+1){
            rep(k,1,w+1){
                if(v[j][k]==1)diff+=sqrt((j-i)*(j-i)+k*k);
            }
        }
        ans=min(ans,diff);
    }

    rep(i,1,h+1){
        double diff=0;
        rep(j,1,h+1){
            rep(k,1,w+1){
                if(v[j][k]==1)diff+=sqrt((j-i)*(j-i)+(w+1-k)*(w+1-k));
            }
        }
        ans=min(ans,diff);
    }

    rep(i,1,w+1){
        double diff=0;
        rep(j,1,h+1){
            rep(k,1,w+1){
                if(v[j][k]==1)diff+=sqrt(j*j+(k-i)*(k-i));
            }
        }
        ans=min(ans,diff);
    }
    
    rep(i,1,w+1){
        double diff=0;
        rep(j,1,h+1){
            rep(k,1,w+1){
                if(v[j][k]==1)diff+=sqrt((h+1-j)*(h+1-j)+(k-i)*(k-i));
            }
        }
        ans=min(ans,diff);
    }

    fcout<<ans<<endl;
    
    return 0;
} 
0