답안 #38856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38856 2018-01-07T10:48:22 Z Abelyan Riddick's Cube (IZhO13_riddicks) C++14
0 / 100
0 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 += c[k] = min(m-i,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 += b[k] = min(n-i,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 Incorrect 0 ms 2016 KB Output isn't correct
7 Halted 0 ms 0 KB -