結果

問題 No.707 書道
ユーザー CleyLCleyL
提出日時 2022-11-07 13:51:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 99,776 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 03:13:37
合計ジャッジ時間 1,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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