結果
| 問題 |
No.707 書道
|
| コンテスト | |
| ユーザー |
tetsuzuki1115
|
| 提出日時 | 2018-08-15 18:16:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 855 ms |
| コンパイル使用メモリ | 100,184 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 09:27:52 |
| 合計ジャッジ時間 | 1,359 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
#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;
}
tetsuzuki1115