結果

問題 No.2094 Symmetry
ユーザー hoktohokto
提出日時 2022-10-07 22:39:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,904 bytes
コンパイル時間 2,670 ms
コンパイル使用メモリ 213,764 KB
実行使用メモリ 21,732 KB
最終ジャッジ日時 2023-09-03 14:07:34
合計ジャッジ時間 11,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,h,t) for(int i=(int)h;i<(int)t;i++)
#define Rrep(i,n) for(int i=(int)n;i>=0;i--)
#define RRep(i,h,t) for(int i=(int)h;i>=(int)t;i--)
#define UNIQ(v) v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
#define Fi first
#define Se second

template<typename T>
bool chmax(T& vmax,const T& v)
{
    if(vmax<v)
    {
        vmax=v;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& vmin,const T& v)
{
    if(vmin>v)
    {
        vmin=v;
        return true;
    }
    return false;
}

using namespace std;

using ll=long long;
using lb=long double;
using veci=vector<int>;
using vec2i=vector<vector<int>>;
using vecll=vector<ll>;
using vec2ll=vector<vector<ll>>;
using p2i=pair<int,int>;
using p2ll=pair<ll,ll>;
using m2i=map<int,int>;
using m2ll=map<ll,ll>;
using msi=map<string,int>;


ll gcd(ll a,ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return ll(a/gcd(a,b))*b;
}

void yn_out(bool b,string yes_out="Yes",string no_out="No")
{
    cout<<(b ? yes_out : no_out)<<endl;
}

ll ceilll(ll a,ll b)
{
    return (a+b-1)/b;
}

const int MOD=1e9+7;
//const int MOD=998244353;
const int dirx[4]={1,0,-1,0};
const int diry[4]={0,1,0,-1};


bool is_symmetry(vector<string> S,int N){
    rep(i,N){
        rep(j,N){
            if(S[i][j]!=S[i][2*N-1-j]) {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout<<fixed<<setprecision(9);
    int N;
    ll K;
    cin>>N>>K;
    vector<string> S(2*N);
    rep(i,2*N){
        cin>>S[i];
    }
    // W:昇順 B:降順
    set<pair<ll,int>> W,B;

    vec2ll C(2*N,vecll(2*N));
    ll ans=-1e16;
    ll sum=0;
    rep(i,2*N){
        rep(j,2*N){
            cin>>C[i][j];
            if(S[i][j]=='.'){
                W.insert({-C[i][j],i*2*N+j});
            }
            else{
                B.insert({C[i][j],i*2*N+j});
                sum+=C[i][j];
            }
        }
    }
    bool symmetry_flag=0;
    if(is_symmetry(S,N)){
        ans=sum+K;
        symmetry_flag=1;
    }
    else{
        ans=sum;
    }
    rep(i,2*N){
        if(W.empty()||B.empty()) break;
        auto [w,wp]=*W.begin();
        auto [b,bp]=*B.begin();
        W.erase(W.begin());
        B.erase(B.begin());
        w*=-1;
        if(b>=w){
            break;
        }
        sum+=w-b;
        W.insert({-b,bp});
        B.insert({w,wp});
        swap(S[wp/(2*N)][wp%(2*N)],S[bp/(2*N)][bp%(2*N)]);
        if(symmetry_flag){
            chmax(ans,sum);
            symmetry_flag=0;
        }
        else if(is_symmetry(S,N)){
            chmax(ans,sum+K);
            symmetry_flag=1;
        }
        else{
            chmax(ans,sum);
        }
    }
    cout<<ans<<endl;
    return 0;
}
0