Submission #97169

# Submission time Handle Problem Language Result Execution time Memory
97169 2019-02-14T08:51:38 Z Kastanda Riddick's Cube (IZhO13_riddicks) C++11
0 / 100
2000 ms 484 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 += min(S[i], n - S[i]);
                for (int i = 0; i < n; i++)
                    sum += min(T[i], m - T[i]);
                Mn = min(Mn, sum);
            }
        }
    }
    return !printf("%d\n", Mn);
}

Compilation message

riddicks.cpp: In function 'int main()':
riddicks.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
riddicks.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &A[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 27 ms 484 KB Output is correct
9 Correct 271 ms 476 KB Output is correct
10 Correct 358 ms 384 KB Output is correct
11 Correct 243 ms 356 KB Output is correct
12 Correct 294 ms 360 KB Output is correct
13 Execution timed out 2021 ms 256 KB Time limit exceeded
14 Halted 0 ms 0 KB -