結果

問題 No.1912 Get together 2
ユーザー 👑 colognecologne
提出日時 2022-04-22 22:59:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 885 bytes
コンパイル時間 2,893 ms
コンパイル使用メモリ 247,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 09:42:30
合計ジャッジ時間 11,546 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> V(N);
    for (int &v : V)
        cin >> v;
    vector<int> S(N);
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < M; j++)
            S[i] += (s[j] == 'o') << j;
    }

    vector<int> Z(1 << M);
    for (int i = 0; i < N; i++)
        Z[S[i]] += V[i];

    for (int i = 0; i < N; i++)
        for (int j = 0; j < (1 << M); ++j)
            if (j & (1 << i))
                Z[j - (1 << i)] += Z[j];


    vector<long> DP(1 << M);
    for (int i = 1; i < (1 << M); i++)
    {
        for (int j = 0; j < M; j++)
            if (i & (1 << j))
            {
                long v =  Z[i - (1 << j)] -  Z[i];
                DP[i] = max(DP[i], DP[i - (1 << j)] + v * v);
            }
    }

    cout << DP.back() << endl;
}
0