# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
97166 | 2019-02-14T08:45:34 Z | Kastanda | Riddick's Cube (IZhO13_riddicks) | C++11 | 5 ms | 512 KB |
#include<bits/stdc++.h> using namespace std; const int MXN = 5; struct Generator { int n, m, cur, MX; Generator (int _n, int _m) { n = _n; m = _m; MX = 1; cur = 0; for (int i = 1; i <= n; i++) MX *= m; } inline vector < int > Next() { vector < int > R; if (cur == MX) return (R); int tmp = cur; for (int i = 0; i < n; i++) R.push_back(tmp % m), tmp /= m; cur ++; return (R); } }; int n, m, A[MXN][MXN], B[MXN][MXN], C[MXN][MXN]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", &A[i][j]); int Mn = 100500; Generator G(m, n); while (1) { vector < int > S = G.Next(); if (!S.size()) break; Generator H(n, m); while (1) { vector < int > T = H.Next(); if (!T.size()) break; for (int j = 0; j < m; j++) for (int i = 0; i < n; i++) B[i][j] = A[(i + S[j]) % n][j]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) C[i][j] = B[i][(j + T[i]) % m]; bool Fail = 0; for (int i = 0; i < n; i++) for (int j = 1; j < m; j++) if (C[i][j] != C[i][j - 1]) Fail = 1; if (Fail) { Fail = 0; for (int i = 1; i < n; i++) for (int j = 0; j < m; j++) if (C[i][j] != C[i - 1][j]) Fail = 1; } if (!Fail) { int sum = 0; for (int i = 0; i < m; i++) sum += S[i]; for (int i = 0; i < n; i++) sum += T[i]; Mn = min(Mn, sum); } } } return !printf("%d\n", Mn); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 5 ms | 256 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |