結果

問題 No.1912 Get together 2
ユーザー chineristACchineristAC
提出日時 2021-08-09 22:11:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,045 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 141,664 KB
実行使用メモリ 32,928 KB
最終ジャッジ日時 2023-09-06 06:42:10
合計ジャッジ時間 8,029 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
32,928 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 17 ms
4,380 KB
testcase_09 AC 30 ms
4,376 KB
testcase_10 AC 35 ms
4,376 KB
testcase_11 AC 32 ms
4,380 KB
testcase_12 AC 84 ms
4,380 KB
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 #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
using namespace std;

#define rep(i,n,c) for (int i=0;i<n;i+=c)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<"\n";
}

ll pow(ll n,ll k){
  ll res = 1;
  while (k){
    if (k&1){
      res *= n;
    }
    n *= n;
    k >>= 1;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int N,M;
  cin>>N>>M;
  vec<ll> V(N);
  for (auto &v:V){
    cin>>v;
  }

  vec<ll> bit(1<<M,0);
  string S;
  int t;
  for (int i=0;i<N;i++){
    cin>>S;
    t = 0;
    for (int j=0;j<M;j++){
      if (S[j]=='o'){
        t += (1<<j);
      }
    }
    bit[t] += V[i];
  }

  auto calc = [bit](int free_group,int o_group){
    ll res = bit[o_group];
    int tmp = free_group;
    while (tmp){
      res += bit[tmp+o_group];
      tmp = (tmp-1) & free_group;
    }
    return res;
  };

  vec<ll> dp(1<<M,0);
  int ALL = (1<<M) - 1;
  ll score;
  for (int i=1;i<(1<<M);i++){
    for (int j=0;j<M;j++){
      t = (1<<j);
      if ((i>>j) & 1){
        score = calc(i-t,t);
        chmax(dp[i],dp[i-t]+score*score);
      }
    }
  }

  cout<<dp[ALL]<<endl;
}
0