結果

問題 No.861 ケーキカット
ユーザー ttttan2ttttan2
提出日時 2019-08-10 00:27:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 145,440 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-26 22:16:46
合計ジャッジ時間 17,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 563 ms
4,376 KB
testcase_01 AC 563 ms
4,380 KB
testcase_02 AC 569 ms
4,376 KB
testcase_03 AC 562 ms
4,380 KB
testcase_04 AC 572 ms
4,376 KB
testcase_05 AC 571 ms
4,376 KB
testcase_06 AC 570 ms
4,380 KB
testcase_07 AC 569 ms
4,376 KB
testcase_08 AC 561 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 569 ms
4,380 KB
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 #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll c[5][5];
ll sum;
ll ans;
bool used[5][5];
pll par[5][5];
void dfs(ll nh,ll nw,ll cnt){
    ans=min(ans,abs(sum-cnt-cnt));
    rep(i,0,4){
        ll nnh=nh+dh[i];
        ll nnw=nw+dw[i];
        if(nnh<0||nnh>=5||nnw<0||nnw>=5)continue;
        if(par[nh][nw].first==nnh&&par[nh][nw].second==nnw){
            par[nh][nw]={-1,-1};
            dfs(nnh,nnw,cnt);
        }
        if(used[nnh][nnw])continue;
        used[nnh][nnw]=true;
        par[nnh][nnw]={nh,nw};
        dfs(nnh,nnw,cnt+c[nnh][nnw]);
        used[nnh][nnw]=false;
        par[nnh][nnw]={-1,-1};
    }
}
int main(){
    rep(i,0,5){
        rep(j,0,5){
            cin>>c[i][j];
            sum+=c[i][j];
            par[i][j]={-1,-1};
        }
    }
    ans=sum;
    used[0][0]=true;
    dfs(0,0,c[0][0]);
    cout<<ans<<endl;
}

0