# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341122 | 2020-12-29T03:19:07 Z | juggernaut | Riddick's Cube (IZhO13_riddicks) | C++14 | 537 ms | 492 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 5 ms | 364 KB | Output is correct |
9 | Correct | 30 ms | 492 KB | Output is correct |
10 | Correct | 31 ms | 364 KB | Output is correct |
11 | Correct | 30 ms | 492 KB | Output is correct |
12 | Correct | 30 ms | 364 KB | Output is correct |
13 | Correct | 537 ms | 492 KB | Output is correct |
14 | Correct | 525 ms | 364 KB | Output is correct |
15 | Correct | 517 ms | 364 KB | Output is correct |
16 | Correct | 520 ms | 492 KB | Output is correct |
17 | Correct | 524 ms | 492 KB | Output is correct |
18 | Correct | 523 ms | 492 KB | Output is correct |
19 | Correct | 520 ms | 492 KB | Output is correct |
20 | Correct | 524 ms | 364 KB | Output is correct |