結果

問題 No.1912 Get together 2
ユーザー RubikunRubikun
提出日時 2022-04-22 22:25:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 3,416 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 202,788 KB
実行使用メモリ 36,708 KB
最終ジャッジ日時 2023-09-06 08:59:46
合計ジャッジ時間 7,543 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 16 ms
4,380 KB
testcase_13 AC 176 ms
36,532 KB
testcase_14 AC 176 ms
36,556 KB
testcase_15 AC 177 ms
36,476 KB
testcase_16 AC 177 ms
36,524 KB
testcase_17 AC 174 ms
36,572 KB
testcase_18 AC 155 ms
36,524 KB
testcase_19 AC 153 ms
36,556 KB
testcase_20 AC 158 ms
36,556 KB
testcase_21 AC 151 ms
36,480 KB
testcase_22 AC 157 ms
36,588 KB
testcase_23 AC 146 ms
36,540 KB
testcase_24 AC 143 ms
36,628 KB
testcase_25 AC 144 ms
36,504 KB
testcase_26 AC 144 ms
36,492 KB
testcase_27 AC 145 ms
36,596 KB
testcase_28 AC 21 ms
4,376 KB
testcase_29 AC 20 ms
4,376 KB
testcase_30 AC 22 ms
4,380 KB
testcase_31 AC 19 ms
4,380 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 136 ms
36,572 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 137 ms
36,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=1LL<<60;

// 高速xxx変換

template<typename T>
vector<T> fzt(vector<T> A,bool wh){
    int n=si(A);
    vector<T> res=A;
    
    for(int i=1;i<n;i*=2){
        for(int j=0;j<n;j++){
            if((j&i)==0){
                if(wh) res[j|i]+=res[j];
                else res[j]+=res[j|i];
            }
        }
    }
    
    return res;
}//wh==0 j⊂x wh==1 x⊂j となるxの和

template<typename T>
vector<T> fmt(vector<T> A,bool wh){
    int n=si(A);
    vector<T> res=A;
    
    for(int i=1;i<n;i*=2){
        for(int j=0;j<n;j++){
            if((j&i)==0){
                if(wh) res[j|i]-=res[j];
                else res[j]-=res[j|i];
            }
        }
    }
    
    return res;
}//wh==0 j⊂x wh==1 x⊂j となるxのfztの逆変換

template<typename T>
vector<T> fwt_and(vector<T> A,vector<T> B){
    int n=si(A);
    A=fzt(A,0);
    B=fzt(B,0);
    vector<T> res(n);
    
    for(int i=0;i<n;i++) res[i]=A[i]*B[i];
    
    res=fmt(res,0);
    
    return res;
}

template<typename T>
vector<T> fwt_or(vector<T> A,vector<T> B){
    int n=si(A);
    A=fzt(A,1);
    B=fzt(B,1);
    vector<T> res(n);
    
    for(int i=0;i<n;i++) res[i]=A[i]*B[i];
    
    res=fmt(res,1);
    
    return res;
}

template<typename T>
vector<T> fwt_xor_sub(vector<T> A,bool t){
    int n=si(A);
    vector<T> res=A;
    
    for(int i=1;i<n;i*=2){
        for(int j=0;j<n;j++){
            if((j&i)==0){
                T x=res[j],y=res[j|i];
                if(t==0){
                    res[j]=x+y;
                    res[j|i]=x-y;
                }else{
                    res[j]=(x+y)/2;
                    res[j|i]=(x-y)/2;
                }// modintのときは/2 を *xにすること(998244353なら*499122177)
            }
        }
    }
    
    return res;
}// t==0 先 t==1 後

template<typename T>
vector<T> fwt_xor(vector<T> A,vector<T> B){
    int n=si(A);
    A=fwt_xor_sub(A,0);
    B=fwt_xor_sub(B,0);
    vector<T> res(n);
    
    for(int i=0;i<n;i++) res[i]=A[i]*B[i];
    
    res=fwt_xor_sub(res,1);
    
    return res;
}// modintのときはfwt_xor_subで/2 を *xにすること(998244353なら*499122177)

ll dp[1<<20];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<ll> V(N);
    for(int i=0;i<N;i++) cin>>V[i];
    
    vector<ll> A(1<<M),neg(1<<M);
    for(int i=0;i<N;i++){
        string S;cin>>S;
        int x=0;
        for(int j=0;j<M;j++){
            if(S[j]=='o') x+=(1<<j);
        }
        A[x]+=V[i];
        neg[(1<<M)-1-x]+=V[i];
    }
    
    neg=fzt(neg,0);
    
    for(int bit=0;bit<(1<<M);bit++) dp[bit]=-INF;
    dp[0]=0;
    
    for(int bit=0;bit<(1<<M);bit++){
        for(int i=0;i<M;i++){
            if(bit&(1<<i)) continue;
            ll X=neg[(1<<M)-1-(bit|(1<<i))]-neg[(1<<M)-1-bit];
            chmax(dp[bit|(1<<i)],dp[bit]+X*X);
        }
    }
    
    cout<<dp[(1<<M)-1]<<endl;
}
0