답안 #38858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38858 2018-01-07T11:00:35 Z Abelyan Riddick's Cube (IZhO13_riddicks) C++14
0 / 100
2000 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 = 0){
	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=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;
}
# 결과 실행 시간 메모리 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 9 ms 2016 KB Output is correct
9 Correct 126 ms 2016 KB Output is correct
10 Correct 119 ms 2016 KB Output is correct
11 Correct 126 ms 2016 KB Output is correct
12 Correct 126 ms 2016 KB Output is correct
13 Execution timed out 2000 ms 2016 KB Execution timed out
14 Halted 0 ms 0 KB -