結果
問題 | No.1912 Get together 2 |
ユーザー |
|
提出日時 | 2021-08-09 22:04:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,046 bytes |
コンパイル時間 | 7,715 ms |
コンパイル使用メモリ | 173,524 KB |
最終ジャッジ日時 | 2025-01-23 17:16:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 WA * 10 TLE * 17 |
ソースコード
#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; int 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; }