Submission #341122

#TimeUsernameProblemLanguageResultExecution timeMemory
341122juggernautRiddick's Cube (IZhO13_riddicks)C++14
100 / 100
537 ms492 KiB
#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)

riddicks.cpp: In function 'int main()':
riddicks.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
riddicks.cpp:42:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |       scanf("%d",&arr[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...