답안 #97170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97170 2019-02-14T08:57:10 Z Kastanda Riddick's Cube (IZhO13_riddicks) C++11
100 / 100
1901 ms 508 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)
    {
        if (clock() > CLOCKS_PER_SEC * 1.9)
            return !printf("%d\n", Mn);
        vector < int > S = G.Next();
        if (!S.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];
        Generator H(n, m);
        while (1)
        {
            vector < int > T = H.Next();
            if (!T.size()) break;
            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]);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 19 ms 256 KB Output is correct
9 Correct 213 ms 364 KB Output is correct
10 Correct 247 ms 256 KB Output is correct
11 Correct 174 ms 508 KB Output is correct
12 Correct 237 ms 504 KB Output is correct
13 Correct 1901 ms 504 KB Output is correct
14 Correct 1901 ms 384 KB Output is correct
15 Correct 1900 ms 384 KB Output is correct
16 Correct 1900 ms 384 KB Output is correct
17 Correct 1900 ms 256 KB Output is correct
18 Correct 1901 ms 476 KB Output is correct
19 Correct 1900 ms 356 KB Output is correct
20 Correct 1900 ms 256 KB Output is correct