結果

問題 No.861 ケーキカット
ユーザー parukiparuki
提出日時 2019-08-10 19:41:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,211 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 170,872 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-26 23:37:52
合計ジャッジ時間 3,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int D[] = { 0,-1,0,1,0 };

const int N = 5;
int C[N][N], share[N][N], vis[N][N];
ll sm[2];

void dfs(int r, int c) {
    if (vis[r][c]++)return;
    int s = share[r][c];
    sm[s] += C[r][c];
    rep(i, 4) {
        int nr = r + D[i], nc = c + D[i + 1];
        if (nr >= 0 && nc >= 0 && nr < N && nc < N && s==share[nc][nr] && !vis[nr][nc]) {
            dfs(nr, nc);
        }
    }
}

void solve() {
    rep(i, N)rep(j, N)cin >> C[i][j];

    const int M = 16;
    vector<pii> P;
    rep(i, 4)P.emplace_back(0, i);
    rep(i, 4)P.emplace_back(i, 4);
    rep(i, 4)P.emplace_back(4, 4 - i);
    rep(i, 4)P.emplace_back(4 - i, 0);
    each(p, P) {
        cout << p.first << ' ' << p.second << endl;
    }

    ll ans = LLONG_MAX;
    rep(i, M)for (int j = i + 1; j <= M; ++j) {
        rep(S, 1 << 9) {
            MEM(share, 0);
            MEM(vis, 0);
            MEM(sm, 0);

            for (int k = i; k < j; ++k) {
                share[P[k].first][P[k].second] = 1;
            }
            rep(k, 9) if (S >> k & 1) {
                int r = k / 3 + 1, c = k % 3 + 1;
                share[r][c] = 1;
            }

            int cnt = 0;
            [&] {
                rep(r, N)rep(c, N)if (!vis[r][c]) {
                    if (cnt++ == 2) {
                        return;
                    }
                    dfs(r, c);
                }
            }();

            if (cnt <= 2) {
                smin(ans, abs(sm[0] - sm[1]));
            }
        }
    }

    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0