# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
676570 | QwertyPi | Riddick's Cube (IZhO13_riddicks) | C++14 | 1 ms | 300 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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++){
shift_c(idx, i);
cx += i != 0;
rec(idx + 1);
shift_c(idx, R - i);
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... |