# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339190 | 2020-12-24T19:46:23 Z | Kerim | Riddick's Cube (IZhO13_riddicks) | C++17 | 531 ms | 364 KB |
#include "stdio.h" 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\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
7 | Correct | 1 ms | 256 KB | Output is correct |
8 | Correct | 3 ms | 256 KB | Output is correct |
9 | Correct | 30 ms | 256 KB | Output is correct |
10 | Correct | 30 ms | 256 KB | Output is correct |
11 | Correct | 30 ms | 256 KB | Output is correct |
12 | Correct | 30 ms | 256 KB | Output is correct |
13 | Correct | 519 ms | 364 KB | Output is correct |
14 | Correct | 527 ms | 256 KB | Output is correct |
15 | Correct | 521 ms | 364 KB | Output is correct |
16 | Correct | 531 ms | 364 KB | Output is correct |
17 | Correct | 524 ms | 352 KB | Output is correct |
18 | Correct | 519 ms | 256 KB | Output is correct |
19 | Correct | 524 ms | 364 KB | Output is correct |
20 | Correct | 522 ms | 352 KB | Output is correct |