結果
問題 | No.707 書道 |
ユーザー |
|
提出日時 | 2017-10-15 16:20:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 532 ms |
コンパイル使用メモリ | 71,612 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 17:46:27 |
合計ジャッジ時間 | 1,013 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
ソースコード
#include <iostream>#include <algorithm>#include <cmath>#include <iomanip>using namespace std;int main(){int H, W;cin >> H >> W;string sample[H];for(int i = 0; i < H; i++){cin >> sample[i];}double ans = 1e9;for(int i = 0; i < H; i++){double this_ans = 0;for(int y = 0; y < H; y++){for(int x = 0; x < W; x++){if(sample[y][x] == '1'){this_ans += sqrt((x + 1) * (x + 1) + (y - i) * (y - i));}}}ans = min(ans, this_ans);}for(int i = 0; i < H; i++){double this_ans = 0;for(int y = 0; y < H; y++){for(int x = 0; x < W; x++){if(sample[y][x] == '1'){this_ans += sqrt((W - x) * (W - x) + (y - i) * (y - i));}}}ans = min(ans, this_ans);}for(int i = 0; i < W; i++){double this_ans = 0;for(int y = 0; y < H; y++){for(int x = 0; x < W; x++){if(sample[y][x] == '1'){this_ans += sqrt((y + 1) * (y + 1) + (x - i) * (x - i));}}}ans = min(ans, this_ans);}for(int i = 0; i < W; i++){double this_ans = 0;for(int y = 0; y < H; y++){for(int x = 0; x < W; x++){if(sample[y][x] == '1'){this_ans += sqrt((H - y) * (H - y) + (x - i) * (x - i));}}}ans = min(ans, this_ans);}cout << setprecision(12) << ans << endl;}