結果

問題 No.2094 Symmetry
ユーザー MagentorMagentor
提出日時 2022-10-07 22:12:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,035 bytes
コンパイル時間 4,215 ms
コンパイル使用メモリ 285,708 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-06-12 18:53:40
合計ジャッジ時間 13,216 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 1 ms
6,940 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (int i = 1; i < (long long)(n); i++)
typedef long long ll;
#pragma GCC target("avx512f")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()

#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint998244353;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
struct unionfind{
  vector<int> par,siz;
  void reset(int n){par.resize(n);siz.resize(n);rep(i,n){par[i]=-1;siz[i]=1;}}
  
  int root(int x){
   if(par[x]==-1){return x;}
   else{return par[x] = root(par[x]);} 
  }
  
  bool issame(int x,int y){
   return root(x)==root(y); 
  }
  
  bool unite(int x,int y){
   x = root(x);y=root(y);
   if(x == y){return false;}
   if(siz[x] < siz[y]){swap(x,y);} 
   par[y] = x;
  siz[x] += siz[y];
  return true; 
  }
  
  
 
int size(int x){
 return siz[root(x)]; 
}
 
};
 
  struct graph{
vector<vector< pair<int,ll> > > val;  

void print(){
 rep(i,val.size()){
  rep(j,val[i].size()){
   cout << val[i][j].first<<"/" <<val[i][j].second << " ";
  }
   cout << endl;
 }
}
void resize(int n){
 val.resize(n); 
}
void add(int n,int k,ll cost){ val[ n ].push_back( pair(k,cost) ); }
void add2(int n,int k,ll cost){ val[ n ].push_back( pair(k,cost) ); val[ k ].push_back( pair(n,cost) );}    
vector<ll> dfs_basic(int a){
 vector<ll>seen(val.size(),-1);
 queue<int> q;q.push(a);seen[a]=0;
 
 while(!q.empty()){
  int wc=q.front();
     q.pop();
  
  rep(i,val[wc].size()){
   if(-1==seen[val[wc][i].first]){q.push(val[wc][i].first);seen[val[wc][i].first]=seen[wc]+val[wc][i].second;} 
  }
 }
 return seen;  
 }
 
    
  vector<ll>dijkstra(int r){
    vector<ll> d(val.size(), INF);
    d[r] = 0;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(P(0, r));
    while (!pq.empty())
    {
        P p = pq.top();
        pq.pop();
        int dist = p.first, u = p.second;
        if (dist > d[u])
            continue;
        for (ll i = 0; i < val[u].size(); i++)
        {
            int v = val[u][i].first, w = val[u][i].second;
            if (d[v] > d[u] + w)
            {
                d[v] = d[u] + w;
                pq.push(P(d[v], v));
            }
        }
    } 
    return d;
  }
   
   ll classcal(){
    std::priority_queue<
      pair<ll,pair<int,int>>,                // 要素の型はint
      std::vector<pair<ll,pair<int,int>>>,   // 内部コンテナはstd::vector (デフォルトのまま)
      std::greater<pair<ll,pair<int,int>>>   // 昇順 (デフォルトはstd::less<T>)
    > pq; 
   // priority_queue<pair<ll,pair<int,int>>> pq;
    ll costt=0;
    rep(i,val.size()){
    rep(j,val[i].size()){
     if(val[i][j].first>i){ 
      pq.push(pair(val[i][j].second,pair(i,val[i][j].first)));
     }
      
    }
   }
   dsu d(val.size());
  while(!pq.empty()){
     pair<ll,pair<int,int>> ee=pq.top();
     pq.pop();
     if(d.same(ee.second.first,ee.second.second)){continue;}
     costt += ee.first;
     d.merge(ee.second.first,ee.second.second);
    }
     return costt;
   }
};
 

int main() {
int n;ll b;cin>>n>>b;
vector<string>s(2*n);rep(i,2*n){cin>>s[i];}
ll v[2*n][2*n];rep(i,2*n){rep(j,2*n){cin>>v[i][j];}}
ll ls = 0;ll rs=0;
rep(i,2*n){rep(j,2*n){
    if(s[i][j]=='#'){
        if(n>j){ls++;}
        else{rs++;}
    }
}}
ll ans=0;
vector<ll>aa(4*n*n);rep(i,2*n){rep(j,2*n){aa[i*2*n+j]=v[i][j];}}
sort(l(aa));reverse(l(aa));
rep(i,ls+rs){ans += aa[i];}
if((ls+rs)%2==0){
    ll anss = 0;
    vector<ll>aaa(2*n*n);rep(i,2*n){rep(j,n){aaa[i*n+j]=v[i][j]+v[i][n*2-j-1];}}
    sort(l(aaa));reverse(l(aaa));
    rep(i,(ls+rs)/2){anss += aaa[i];}
    cout << max(ans,anss+b)<<endl;
}
else{
    cout<<ans<<endl;
}
}




0