結果

問題 No.861 ケーキカット
ユーザー merom686merom686
提出日時 2019-08-10 00:29:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,293 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 79,592 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-26 22:16:52
合計ジャッジ時間 5,395 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    constexpr int N = 5;

    int c[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
        }
    }

    int p[16];
    for (int h = 0; h < 4; h++) {
        p[h] = h;
        p[h + 4] = 4 + h * N;
        p[h + 8] = 24 - h;
        p[h + 12] = 20 - h * N;
    }

    int d[N][N];
    int d0;
    ll s;
    int x;
    function<void(int, int)> f = [&](int i, int j) {
        if (d[i][j] != d0) return;
        s += c[i][j];
        x++;
        d[i][j] ^= 4;
        if (i > 0) f(i - 1, j);
        if (i < N - 1) f(i + 1, j);
        if (j > 0) f(i, j - 1);
        if (j < N - 1) f(i, j + 1);
    };

    ll r = 1LL << 60;
    for (int k = 0; k < 16; k++) {
        for (int l = 1; l <= 16; l++) {
            for (int h = 0; h < 16; h++) {
                d[0][p[(k + h) % 16]] = h < l;
            }
            for (int h = 0; h < 1 << 9; h++) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        d[i + 1][j + 1] = h >> (i * 3 + j) & 1;
                    }
                }
                s = 0;
                x = 0;
                for (int a = 0; a < 2; a++) {
                    int e = p[k];
                    if (a == 0) {
                        e = -1;
                        for (int h = 0; h < N * N; h++) {
                            if (d[0][h] == 0) {
                                e = h;
                                break;
                            }
                        }
                        if (e < 0) continue;
                    }
                    int i = e / N, j = e % N;
                    d0 = a;
                    f(i, j);
                    s *= -1;
                }
                if (x != N * N) continue;
                r = min(r, abs(s));

                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        d[i][j] &= ~4;
                    }
                }
            }
        }
    }

    cout << r << endl;

    return 0;
}
0