結果

問題 No.707 書道
ユーザー tsutaj
提出日時 2018-06-29 22:40:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 100,092 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-07-01 00:02:41
合計ジャッジ時間 1,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
int H, W;
char board[60][60];
double solve(int lx, int rx, int ly, int ry) {
double mi = 1e100;
for(int x=lx; x<=rx; x++) {
for(int y=ly; y<=ry; y++) {
double sum = 0.0;
for(int i=0; i<H; i++) {
for(int j=0; j<W; j++) {
if(board[i][j] == '0') continue;
int Dx = x - i, Dy = y - j;
sum += sqrt((double)Dx * Dx + Dy * Dy);
}
}
// printf("x = %lld, y = %lld, sum = %.12f\n", x, y, sum);
chmin(mi, sum);
}
}
return mi;
}
signed main() {
cin >> H >> W;
for(int i=0; i<H; i++) {
for(int j=0; j<W; j++) {
cin >> board[i][j];
}
}
double ans = 1e100;
chmin(ans, solve(0, H-1, -1, -1));
chmin(ans, solve(0, H-1, W, W));
chmin(ans, solve(-1, -1, 0, W-1));
chmin(ans, solve(H, H, 0, W-1));
cout << setprecision(12) << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0