# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676574 | QwertyPi | Riddick's Cube (IZhO13_riddicks) | C++14 | 1 ms | 296 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 a[5][5];
int R, C;
void shift_r(int r, int v){
int b[5];
for(int i = 0; i < C; i++){
b[i] = a[r][(i + v) % C];
}
for(int i = 0; i < C; i++){
a[r][i] = b[i];
}
}
void shift_c(int c, int v){
int b[5];
for(int i = 0; i < R; i++){
b[i] = a[(i + v) % R][c];
}
for(int i = 0; i < R; i++){
a[i][c] = b[i];
}
}
int ans = 100500;
int cx = 0;
void test(){
bool all_eq = true;
for(int i = 0; i < R; i++){
for(int j = 1; j < C; j++){
all_eq &= a[i][j] == a[i][0];
}
}
if(all_eq) ans = min(ans, cx);
int b[5];
for(int i = 0; i < C; i++){
b[i] = a[0][i];
}
map<int, int> M;
for(int i = 0; i < R; i++){
bool r_eq = false;
for(int tr = 0; tr < C; tr++){
bool eq = true;
for(int j = 0; j < C; j++){
eq &= b[j] == a[i][j];
}
r_eq |= eq;
if(eq) M[tr]++;
shift_r(i, 1);
}
if(!r_eq) return;
}
for(auto i : M){
ans = min(ans, cx + R - i.second);
}
}
void rec(int idx){
if(idx == C){
test();
return;
}
for(int i = 0; i < R; i++){
cx += i != 0;
rec(idx + 1);
shift_c(idx, 1);
cx -= i != 0;
}
}
int main(){
cin >> R >> C;
for(int i = 0; i < R; i++){
for(int j = 0; j < C; j++){
cin >> a[i][j];
}
}
rec(0);
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |