Created
May 16, 2019 13:07
-
-
Save whatalnk/8562ccad99bb12299e9eb23981e59a92 to your computer and use it in GitHub Desktop.
AtCoder ABC #099 D - Good Grid
This file contains hidden or 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 <iostream> | |
using namespace std; | |
const int MAX_C = 30; | |
static int N, C; | |
static int D[MAX_C][MAX_C]; | |
static int t[3][MAX_C]; | |
int solve(); | |
int solve() { | |
int ans = 1 << 30; | |
for (int i = 0; i < C; i++) { | |
for (int j = 0; j < C; j++) { | |
for (int k = 0; k < C; k++) { | |
if (i != j && j != k && k != i) { | |
int tt = 0; | |
for (int l = 0; l < C; l++) { | |
tt += D[l][i] * t[0][l]; | |
tt += D[l][j] * t[1][l]; | |
tt += D[l][k] * t[2][l]; | |
} | |
ans = min(ans, tt); | |
} | |
} | |
} | |
} | |
return ans; | |
} | |
int main() { | |
cin >> N >> C; | |
int x; | |
for (int i = 0; i < C; i++) { | |
for (int j = 0; j < C; j++) { | |
cin >> x; | |
D[i][j] = x; | |
} | |
} | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { | |
cin >> x; | |
t[(i + j) % 3][x - 1] += 1; | |
} | |
} | |
cout << solve() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment