結果
| 問題 | 
                            No.2094 Symmetry
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-07 21:48:03 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 74 ms / 2,000 ms | 
| コード長 | 998 bytes | 
| コンパイル時間 | 2,143 ms | 
| コンパイル使用メモリ | 207,588 KB | 
| 最終ジャッジ日時 | 2025-02-07 23:09:46 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 34 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    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 cntB = 0;
    rep(i,2*N)rep(j,2*N) if(S[i][j] == '#') cntB++;
    ll ans1 = [N, C, cntB]() {
        vector<ll> V;
        rep(i,2*N)rep(j,2*N) V.push_back(C[i][j]);
        sort(V.rbegin(), V.rend());
        ll ans = 0;
        rep(i,cntB) ans += V[i];
        return ans;
    }();
    ll ans2 = [N, K, C, cntB]() {
        if(cntB % 2 == 1) return numeric_limits<ll>::min();
        vector<ll> V;
        rep(i,2*N)rep(j,N) V.push_back(C[i][j] + C[i][2 * N - 1 - j]);
        sort(V.rbegin(), V.rend());
        ll ans = 0;
        rep(i,cntB/2) ans += V[i];
        return ans + K;
    }();
    cout << max(ans1, ans2) << endl;
}