# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341122 | juggernaut | Riddick's Cube (IZhO13_riddicks) | C++14 | 537 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int arr[5][5],n,m;
void row(int x){
int tmp=arr[x][m-1];
for(int i=m-1;i>0;i--)
arr[x][i]=arr[x][i-1];
arr[x][0]=tmp;
}
void col(int x){
int tmp=arr[n-1][x];
for(int i=n-1;i>0;i--)
arr[i][x]=arr[i-1][x];
arr[0][x]=tmp;
}
int ans=100500;
void son(int x){
int ok=1;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
ok&=(arr[i][j]==arr[i][0]);
if(ok){if(ans>x)ans=x;}ok=1;
for(int j=0;j<m;j++)
for(int i=0;i<n;i++)
ok&=(arr[i][j]==arr[0][j]);
if(ok){if(ans>x)ans=x;}
}
void g(int x,int cur){
if(x==n){son(cur);return;}
for(int i=0;i<m;i++)
g(x+1,cur+(i>m-i?m-i:i)),row(x);
}
void f(int x,int cur){
if(x==m){g(0,cur);return;}
for(int i=0;i<n;i++)
f(x+1,cur+(i>n-i?n-i:i)),col(x);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&arr[i][j]);
f(0,0);printf("%d",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |