Submission #3446180


Source Code Expand

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;

ll N, C;
ll d[31][31] = {};
ll c[501][501] = {};
ll e[30][3] = {};
int main()
{
	cin >> N >> C;
	repe(i, 1, C)repe(j, 1, C)cin >> d[i][j];
	repe(i, 1, N)repe(j, 1, N)cin >> c[i][j];

	repe(k, 1, C) {
		repe(i, 1, N)repe(j, 1, N) {
			e[k][(i + j) % 3] += d[c[i][j]][k];
		}
	}

	ll ans = 1 << 30;
	repe(i, 1, C) {
		repe(j, 1, C) {
			if (i != j) {
				repe(k, 1, C) {
					if (i != k && j != k) {
						ans = min(ans, e[i][0] + e[j][1] + e[k][2]);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Good Grid
User butanokakuni_d1
Language C++14 (GCC 5.4.1)
Score 400
Code Size 801 Byte
Status AC
Exec Time 61 ms
Memory 2176 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt AC 60 ms 2176 KB
02.txt AC 46 ms 1920 KB
03.txt AC 1 ms 256 KB
04.txt AC 15 ms 1280 KB
05.txt AC 1 ms 256 KB
06.txt AC 61 ms 2176 KB
07.txt AC 59 ms 2176 KB
08.txt AC 59 ms 2176 KB
09.txt AC 13 ms 1280 KB
10.txt AC 6 ms 896 KB
11.txt AC 10 ms 1152 KB
12.txt AC 15 ms 1408 KB
13.txt AC 56 ms 2176 KB
14.txt AC 44 ms 2048 KB
15.txt AC 59 ms 2176 KB
16.txt AC 25 ms 1536 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB