# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501482 | keta_tsimakuridze | Riddick's Cube (IZhO13_riddicks) | C++14 | 1243 ms | 324 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>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 6, mod = 1e9 + 7; // !
int t, b[N][N], a[N][N],c[N][N], n, m, f[12], ans = 0;
void go(int id) {
if(id == n + m + 1) {
int cnt = 0;
for(int j = 1; j <= m; j++) {
cnt += min(f[j], n - f[j]);
for(int i = 1; i <= n - f[j]; i++) c[i][j] = a[i + f[j]][j];
for(int i = n - f[j] + 1; i <= n; i++) c[i][j] = a[i - (n - f[j])][j];
}
for(int j = 1; j <= n; j++) {
cnt += min(f[j + m], m - f[j + m]);
for(int i = 1; i <= m - f[j + m]; i++) b[j][i] = c[j][i + f[j + m]];
for(int i = m - f[j + m] + 1; i <= m; i++) b[j][i] = c[j][i - (m - f[j + m])];
}
int F = 0, f = 0;
for(int i = 1; i <= n; i++) {
for(int j = 2; j <= m; j++) if(b[i][j] != b[i][j - 1]) F = 1;
}
for(int j = 1; j <= m; j++) {
for(int i = 2; i <= n; i++) if(b[i][j] != b[i - 1][j]) f = 1;
}
if(!(f && F)) ans = min(ans, cnt);
return;
}
if(id <= m) {
for(int j = 0; j < n; j++) {
f[id] = j;
go(id + 1);
}
}
else for(int j = 0; j < m; j++) f[id] = j, go(id + 1);
}
main(){
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) cin >> a[i][j];
}
ans = 100500;
go(1); cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |