結果

問題 No.2094 Symmetry
ユーザー shkiiii_shkiiii_
提出日時 2022-10-07 22:30:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,328 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 175,728 KB
実行使用メモリ 14,408 KB
最終ジャッジ日時 2024-06-12 19:30:39
合計ジャッジ時間 6,083 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 WA * 5 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
// #define MOD 998244353


int main(){
  
  ll n,K;
  cin >> n >> K;
  vector<string> s(2*n);
  rep(i,2*n)cin >> s[i];
  vector<vector<ll>> c(2*n,vector<ll>(2*n));
  rep(i,2*n)rep(j,2*n)cin >> c[i][j];
  int cnt = 0;
  rep(i,2*n)rep(j,2*n)cnt += (s[i][j] == '#');
  ll res = -(1ll << 50);
  {
    vector<ll> dp(cnt+1,-(1ll << 60));
    dp[0] = 0;
    rep(i,2*n){
      vector<ll> DP(cnt+1,-(1ll << 60));
      rep(j,n)rep(k,cnt+1){
        if(k+2 <= cnt)DP[k+2] = max(DP[k+2],dp[k] + c[i][j] + c[i][2*n-j-1]);
        DP[k] = max(DP[k],dp[k]);
      }
      swap(dp,DP);
    }
    res = dp[cnt] + K;
  }
  {
    vector<ll> dp(cnt+1,-(1ll << 60));
    dp[0] = 0;
    rep(i,2*n){
      vector<ll> DP(cnt+1,-(1ll << 60));
      rep(j,2*n)rep(k,cnt+1){
        if(k+1 <= cnt)DP[k+1] = max(DP[k+1],dp[k] + c[i][j]);
        DP[k] = max(DP[k],dp[k]);
      }
      swap(dp,DP);
    }
    res = max(res,dp[cnt]);
  }
  cout << res << "\n";

  

  return 0;
}
0