結果
| 問題 |
No.861 ケーキカット
|
| コンテスト | |
| ユーザー |
ttttan2
|
| 提出日時 | 2019-08-10 00:32:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,539 bytes |
| コンパイル時間 | 1,961 ms |
| コンパイル使用メモリ | 159,620 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 16:03:46 |
| 合計ジャッジ時間 | 13,699 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 14 |
ソースコード
#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};
used[i][j]=false;
}
}
ans=sum;
used[0][0]=true;
dfs(0,0,c[0][0]);
cout<<ans<<endl;
}
ttttan2