結果

問題 No.861 ケーキカット
ユーザー CleyLCleyL
提出日時 2019-08-09 22:44:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 883 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 64,444 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-26 21:01:24
合計ジャッジ時間 4,687 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
#define push_back pb
int mp[5][5];
bool lock[5][5];
long long sm;
void init(){
  for(int i = 0; 5 > i; i++){
    for(int j = 0; 5 > j; j++){
      lock[i][j] = false;
    }
  }
}
long long solve(int i,int j, int nwp){
  long long ans = sm;
  nwp += mp[i][j];
  lock[i][j] = true;
  if(sm/2 <= nwp){
    return nwp;
  }
  if(i != 0)ans = min(ans,solve(i-1,j,nwp));
  if(j != 0)ans = min(ans,solve(i,j-1,nwp));
  if(i != 4)ans = min(ans,solve(i+1,j,nwp));
  if(j != 4)ans = min(ans,solve(i,j+1,nwp));
  lock[i][j] = false;
  return ans;
}

int main(){
  sm = 0;
  for(int i = 0; 5 > i; i++){
    for(int j = 0; 5 > j; j++){
      cin>>mp[i][j];
      sm += mp[i][j];
    }
  }
  long long mn = sm;
  for(int i = 0; 5 > i; i++){
    for(int j = 0; 5 > j; j++){
      init();
      mn = min(mn,solve(i,j,0));
    }
  }
  cout << sm-mn*2 <<endl;
}
0