Submission #97166

# Submission time Handle Problem Language Result Execution time Memory
97166 2019-02-14T08:45:34 Z Kastanda Riddick's Cube (IZhO13_riddicks) C++11
0 / 100
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

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 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 -