結果

問題 No.707 書道
ユーザー 👑 CleyL
提出日時 2022-11-07 13:51:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 102,660 KB
最終ジャッジ日時 2025-02-08 19:08:41
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  vector<vector<char>> A(h,vector<char>(w));
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      cin>>A[i][j];
    }
  }
  long double ans = 1e9;
  for(int i = 0; h > i; i++){
    // -1,w+1
    long double tmp = 0,tmp2 = 0;
    for(int j = 0; h > j; j++){
      for(int k = 0; w > k; k++){
        if(A[j][k] == '1'){
          tmp += sqrt((k+1)*(k+1)+(j-i)*(j-i));
          tmp2 += sqrt((w-k)*(w-k)+(j-i)*(j-i));
        }
      }
    }
    ans = min(ans,min(tmp,tmp2));
  }
  for(int i = 0; w > i; i++){
    // -1,w+1
    long double tmp = 0,tmp2 = 0;
    for(int j = 0; h > j; j++){
      for(int k = 0; w > k; k++){
        if(A[j][k] == '1'){
          tmp += sqrt((j+1)*(j+1)+(k-i)*(k-i));
          tmp2 += sqrt((h-j)*(h-j)+(k-i)*(k-i));
        }
      }
    }
    ans = min(ans,min(tmp,tmp2));
  }
  cout << fixed << setprecision(10) << ans << endl;
}
0