# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
996547 | MilosMilutinovic | Riddick's Cube (IZhO13_riddicks) | C++14 | 1389 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int res = 100500;
auto ShiftRow = [&](int x) {
vector<int> v;
for (int y = 0; y < m; y++) {
v.push_back(a[x][(y + 1) % m]);
}
for (int y = 0; y < m; y++) {
a[x][y] = v[y];
}
};
auto ShiftCol = [&](int y) {
vector<int> v;
for (int x = 0; x < n; x++) {
v.push_back(a[(x + 1) % n][y]);
}
for (int x = 0; x < n; x++) {
a[x][y] = v[x];
}
};
auto Good = [&]() {
{
bool ok = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ok = (ok & (a[i][j] == a[i][0]));
}
}
if (ok) {
return true;
}
}
{
bool ok = true;
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
ok = (ok & (a[i][j] == a[0][j]));
}
}
if (ok) {
return true;
}
}
return false;
};
function<void(int, int)> GoX = [&](int x, int cur) {
if (x == n) {
if (Good()) {
res = min(res, cur);
}
return;
}
for (int i = 0; i < m; i++) {
GoX(x + 1, cur + min(i, m - i));
ShiftRow(x);
}
};
function<void(int, int)> GoY = [&](int y, int cur) {
if (y == m) {
GoX(0, cur);
return;
}
for (int i = 0; i < n; i++) {
GoY(y + 1, cur + min(i, n - i));
ShiftCol(y);
}
};
GoY(0, 0);
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |