結果

問題 No.707 書道
ユーザー naotomannaotoman
提出日時 2018-08-03 00:45:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 85,764 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 21:14:08
合計ジャッジ時間 1,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int H, W;
char gr[60][60];
vector<int> x;
vector<int> y;
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed;
    cin >> H >> W;
    REP(i, H) {
        string s;
        cin >> s;
        REP(j, W) {
            gr[i+1][j+1] = s[j];
        }
    }

    REP(i, H) x.push_back(0);
    UP(i, 1, W) x.push_back(i);
    UP(i, 1, W) x.push_back(i);
    REP(i, H) x.push_back(W+1);

    REP(i, H) y.push_back(i+1);
    UP(i, 1, W) y.push_back(0);
    UP(i, 1, W) y.push_back(H+1);
    REP(i, H) y.push_back(i+1);

    double ans = 1<<30;
    REP(i, 2*H+2*W) {
        double now = 0;
        UP(l, 1, H) {
            UP(m, 1, W) {
                if(gr[l][m] == '1') {
                    int xx = x[i] - m;
                    int yy = y[i] - l;
                    now += sqrt(xx*xx + yy*yy);
                }
            }
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
}
0