Submission #676570

#TimeUsernameProblemLanguageResultExecution timeMemory
676570QwertyPiRiddick's Cube (IZhO13_riddicks)C++14
0 / 100
1 ms300 KiB
#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 timeMemoryGrader output
Fetching results...