Submission #742208

#TimeUsernameProblemLanguageResultExecution timeMemory
742208rainboyRiddick's Cube (IZhO13_riddicks)C11
100 / 100
156 ms288 KiB
#include <stdio.h> #define N 5 #define M 5 #define INF 100500 int min(int a, int b) { return a < b ? a : b; } int aa[N][M], n, m; int check() { int i, j, good; good = 1; for (i = 0; i < n; i++) for (j = 1; j < m; j++) if (aa[i][j] != aa[i][j - 1]) { good = 0; goto out1; } out1: if (good) return 1; good = 1; for (j = 0; j < m; j++) for (i = 1; i < n; i++) if (aa[i][j] != aa[i - 1][j]) { good = 0; goto out2; } out2: return good; } int solve2(int i, int d) { int j, k, tmp, ans; if (i == n) return check() ? d : INF; ans = INF; for (k = 0; k < m; k++) { ans = min(ans, solve2(i + 1, d + min(k, m - k))); tmp = aa[i][0]; for (j = 0; j + 1 < m; j++) aa[i][j] = aa[i][j + 1]; aa[i][m - 1] = tmp; } return ans; } int solve1(int j, int d) { int i, k, tmp, ans; if (j == m) return solve2(0, d); ans = INF; for (k = 0; k < n; k++) { ans = min(ans, solve1(j + 1, d + min(k, n - k))); tmp = aa[0][j]; for (i = 0; i + 1 < n; i++) aa[i][j] = aa[i + 1][j]; aa[n - 1][j] = tmp; } return ans; } int main() { int i, j; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &aa[i][j]); printf("%d\n", solve1(0, 0)); return 0; }

Compilation message (stderr)

riddicks.c: In function 'main':
riddicks.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
riddicks.c:73:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...