結果

問題 No.2094 Symmetry
ユーザー twooimp2twooimp2
提出日時 2024-03-30 17:27:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 6,706 ms
コンパイル使用メモリ 310,520 KB
実行使用メモリ 9,516 KB
最終ジャッジ日時 2024-03-30 17:27:19
合計ジャッジ時間 12,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main(){
  IO();
  ll n,k;
  cin>>n>>k;
  vector<string> s(2*n);
  for(ll i=0;i<2*n;i++){
    cin>>s[i];
  }
  vector<vector<ll>> c(2*n,vector<ll>(2*n));
  for(ll i=0;i<2*n;i++){
    for(ll j=0;j<2*n;j++){
      cin>>c[i][j];
    }
  }
  ll cb=0;
  for(ll i=0;i<2*n;i++){
    for(ll j=0;j<2*n;j++){
      if(s[i][j]=='#'){
        cb++;
      }
    }
  }
  vector<ll> v;
  for(ll i=0;i<2*n;i++){
    for(ll j=0;j<2*n;j++){
      v.push_back(c[i][j]);
    }
  }
  sort(v.rbegin(),v.rend());
  ll ans=0;
  for(ll i=0;i<cb;i++){
    ans+=v[i];
  }
  if(cb%2!=0){
    cout<<ans<<endl;
    exit(0);
  }
  vector<ll> v2;
  for(ll i=0;i<2*n;i++){
    for(ll j=0;j<n;j++){
      v2.push_back(c[i][j]+c[i][2*n-1-j]);
    }
  }
  sort(v2.rbegin(),v2.rend());
  ll tmp=0;
  for(ll i=0;i<cb/2;i++){
    tmp+=v2[i];
  }
  tmp+=k;
  ans=max(ans,tmp);
  cout<<ans<<endl;
}
0