Submission #38857

# Submission time Handle Problem Language Result Execution time Memory
38857 2018-01-07T10:55:50 Z Abelyan Riddick's Cube (IZhO13_riddicks) C++14
0 / 100
6 ms 2016 KB
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;

int a[5][5],b[5],c[5],d[5][5],qan,mn=INT_MAX;
int n, m;

void check(){
	bool mb = true;
	for (int i = 0; i < n; i++){
		int qur = d[i][0];
		for (int j = 1; j < m; j++){
			if (d[i][j] != qur){
				mb = false;
				break;
			}
		}
		if (!mb) break;
	}
	if (mb){
		if (qan < mn) mn = qan;
		return;
	}
	mb = true;
	for (int j = 0; j < m; j++){
		int qur = d[0][j];
		for (int i = 1; i < n; i++){
			if (d[i][j] != qur){
				mb = false;
				break;
			}
		}
		if (!mb){
			return;
		}
	}
	if (qan < mn) mn = qan;
}

void solve(){
	/*
	for (int i = 0; i < n; i++){
		cout << c[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < m; i++){
		cout << b[i] << " ";
	}
	cout << endl;
	*/

	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			d[(i + b[j]) % n][(j + c[(i + b[j]) % n]) % m] = a[i][j];
		}
	}
	/*
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	cout << qan;
	cout << endl << endl;
	*/
	check();
}

void solve2(int k = 1){
	if (k == n){
		solve();
		return;
	}
	for (int i = 0; i < m; i++){
		qan += min(m-i,i);
		c[k] = i;
		solve2(k + 1);
		qan -= min(m-i,i);
	}
}


void solve1(int k=1){
	if (k == 1) qan = 0;
	if (k == m){
		solve2();
		return;
	}
	for (int i = 0; i < n; i++){
		qan += min(n-i,i);
		b[k] = i;
		solve1(k + 1);
		qan -= min(n-i,i);
	}
}


int main(){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	solve1();
	if (mn == INT_MAX){
		cout << 100500 << endl;
		return 0;
	}
	cout << mn << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
3 Correct 0 ms 2016 KB Output is correct
4 Correct 0 ms 2016 KB Output is correct
5 Correct 0 ms 2016 KB Output is correct
6 Correct 0 ms 2016 KB Output is correct
7 Correct 0 ms 2016 KB Output is correct
8 Correct 0 ms 2016 KB Output is correct
9 Correct 3 ms 2016 KB Output is correct
10 Correct 3 ms 2016 KB Output is correct
11 Incorrect 6 ms 2016 KB Output isn't correct
12 Halted 0 ms 0 KB -