Submission #226367

#TimeUsernameProblemLanguageResultExecution timeMemory
226367emil_physmathRiddick's Cube (IZhO13_riddicks)C++17
0 / 100
2091 ms504 KiB
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <cmath> using namespace std; using llong = long long; int ans = 100500; int a[5][5]; int n, m; inline int Val(const vector<int>& col, const vector<int>& row) { static int b[5][5]; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) b[i][j] = a[i][j]; int res = 0; for (int j = 0; j < m; ++j) { res += min(col[j], n - col[j]); vector<int> cur(n); for (int i = 0; i < n; ++i) cur[i] = b[i][j]; rotate(cur.begin(), cur.begin() + col[j], cur.end()); for (int i = 0; i < n; ++i) b[i][j] = cur[i]; } for (int i = 0; i < n; ++i) { res += min(row[i], m - row[i]); vector<int> cur(m); for (int j = 0; j < m; ++j) cur[j] = b[i][j]; rotate(cur.begin(), cur.begin() + row[i], cur.end()); for (int j = 0; j < m; ++j) b[i][j] = cur[j]; } bool ans1 = true, ans2 = true; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { if (b[i][j] != b[i][0]) ans1 = false; if (b[i][j] != b[0][j]) ans2 = false; } if (!ans1 && !ans2) return 100500; return res; } void Solve(vector<int>& col, vector<int>& row) { if (col.size() == m && row.size() == n) { ans = min(ans, Val(col, row)); return; } if (col.size() == m) { row.push_back(0); for (row.back() = 0; row.back() < m; ++row.back()) Solve(col, row); row.pop_back(); } else { col.push_back(0); for (col.back() = 0; col.back() < n; ++col.back()) Solve(col, row); col.pop_back(); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; vector<int> col, row; Solve(col, row); cout << ans; }

Compilation message (stderr)

riddicks.cpp: In function 'void Solve(std::vector<int>&, std::vector<int>&)':
riddicks.cpp:51:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (col.size() == m && row.size() == n)
         ~~~~~~~~~~~^~~~
riddicks.cpp:51:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (col.size() == m && row.size() == n)
                            ~~~~~~~~~~~^~~~
riddicks.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (col.size() == m)
         ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...