結果

問題 No.1912 Get together 2
ユーザー pockynypockyny
提出日時 2023-01-28 14:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 70,416 KB
実行使用メモリ 20,760 KB
最終ジャッジ日時 2023-09-11 04:03:18
合計ジャッジ時間 9,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,452 KB
testcase_01 AC 2 ms
5,400 KB
testcase_02 AC 2 ms
5,460 KB
testcase_03 AC 2 ms
5,400 KB
testcase_04 AC 2 ms
5,528 KB
testcase_05 AC 2 ms
5,460 KB
testcase_06 AC 2 ms
5,400 KB
testcase_07 AC 2 ms
5,468 KB
testcase_08 AC 22 ms
5,768 KB
testcase_09 AC 17 ms
5,684 KB
testcase_10 AC 30 ms
6,056 KB
testcase_11 AC 22 ms
5,748 KB
testcase_12 AC 33 ms
6,020 KB
testcase_13 AC 221 ms
20,640 KB
testcase_14 AC 222 ms
20,492 KB
testcase_15 AC 221 ms
20,524 KB
testcase_16 AC 222 ms
20,572 KB
testcase_17 AC 222 ms
20,640 KB
testcase_18 AC 216 ms
20,576 KB
testcase_19 AC 218 ms
20,712 KB
testcase_20 AC 214 ms
20,760 KB
testcase_21 AC 215 ms
20,640 KB
testcase_22 AC 213 ms
20,704 KB
testcase_23 AC 212 ms
20,644 KB
testcase_24 AC 212 ms
20,512 KB
testcase_25 AC 214 ms
20,504 KB
testcase_26 AC 212 ms
20,716 KB
testcase_27 AC 212 ms
20,572 KB
testcase_28 AC 54 ms
6,436 KB
testcase_29 AC 52 ms
6,312 KB
testcase_30 AC 57 ms
6,316 KB
testcase_31 AC 48 ms
6,240 KB
testcase_32 AC 49 ms
6,244 KB
testcase_33 AC 193 ms
20,508 KB
testcase_34 AC 2 ms
5,460 KB
testcase_35 AC 202 ms
20,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
ll dp[1<<20],fz[1<<20],val[200010],inf = 1000000000000000000;
int main(){
    int i,j,k,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> val[i];
    for(i=0;i<n;i++){
        string s; cin >> s;
        int x = 0;
        for(j=0;j<m;j++){
            if(s[j]=='o') x += 1<<j;
        }
        fz[x] += val[i];
    }
    for(j=0;j<m;j++){
        for(i=0;i<(1<<m);i++){
            if(i>>j&1) fz[i] += fz[i^(1<<j)];
        }
    }
    for(i=0;i<(1<<m);i++) dp[i] = -inf;
    dp[0] = 0;
    for(i=1;i<(1<<m);i++){
        for(j=0;j<m;j++){
            if(i>>j&1){
                ll num = fz[i] - fz[i^(1<<j)];
                dp[i] = max(dp[i],dp[i^(1<<j)] + num*num);
            }
        }
    }
    cout << dp[(1<<m) - 1] << "\n";
}
0