結果

問題 No.1912 Get together 2
ユーザー 👑 colognecologne
提出日時 2022-04-22 23:03:15
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 247,644 KB
実行使用メモリ 16,380 KB
最終ジャッジ日時 2023-09-06 09:47:09
合計ジャッジ時間 8,476 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 15 ms
4,376 KB
testcase_10 AC 26 ms
4,376 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 29 ms
4,380 KB
testcase_13 AC 184 ms
16,232 KB
testcase_14 AC 184 ms
16,360 KB
testcase_15 AC 185 ms
16,212 KB
testcase_16 AC 184 ms
16,380 KB
testcase_17 AC 186 ms
16,208 KB
testcase_18 AC 187 ms
16,208 KB
testcase_19 AC 187 ms
16,208 KB
testcase_20 AC 186 ms
16,360 KB
testcase_21 AC 186 ms
16,212 KB
testcase_22 AC 188 ms
16,208 KB
testcase_23 AC 185 ms
16,212 KB
testcase_24 AC 182 ms
16,256 KB
testcase_25 AC 184 ms
16,260 KB
testcase_26 AC 184 ms
16,284 KB
testcase_27 AC 188 ms
16,292 KB
testcase_28 AC 49 ms
4,380 KB
testcase_29 AC 46 ms
4,380 KB
testcase_30 AC 50 ms
4,376 KB
testcase_31 AC 43 ms
4,380 KB
testcase_32 AC 44 ms
4,380 KB
testcase_33 AC 186 ms
16,300 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 180 ms
16,232 KB
権限があれば一括ダウンロードができます

ソースコード

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 < M; i++)
        for (int j = 0; j < (1 << M); ++j)
            if (j & (1 << i))
                Z[j] += Z[j - (1 << i)];

    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