Created
December 11, 2017 13:10
-
-
Save mi6112ogit/db0f1ff0fa9465a8fff11b23bf6a3c95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
//#define int long long | |
#define FOR(i, j, k) for(int i = j; i < k; ++i) | |
#define rep(i, j) FOR(i, 0, j) | |
#define INF 1e9 | |
#define LINF 1e18 | |
#define fi first | |
#define se second | |
typedef unsigned long long ull; | |
typedef pair<int, int> P; | |
typedef pair<int, P> Pi; | |
typedef pair<P, P> PP; | |
const int MOD = 1e9 + 7; | |
const int dy[] = { 0, 0, 1, -1 }; | |
const int dx[] = { 1, -1, 0, 0 }; | |
template <class T> void chmin(T& a, const T& b) { a = min(a, b); } | |
template <class T> void chmax(T& a, const T& b) { a = max(a, b); } | |
int h, w; | |
int a[30][30]; | |
signed main() { | |
cin.tie(0); | |
ios::sync_with_stdio(false); | |
cin >> h >> w; | |
rep(i, h) rep(j, w) cin >> a[i][j]; | |
int res = INF; | |
rep(i, h) rep(j, w) { | |
int latte = 0; | |
rep(k, h) rep(l, w) { | |
latte += min(abs(i - k), abs(j - l)) * a[k][l]; | |
} | |
chmin(res, latte); | |
} | |
cout << res << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment