結果
問題 |
No.3219 Ruler to Maximize
|
ユーザー |
|
提出日時 | 2025-09-17 11:38:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,354 bytes |
コンパイル時間 | 6,040 ms |
コンパイル使用メモリ | 335,820 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-17 11:39:00 |
合計ジャッジ時間 | 8,248 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; const ll MOD = 998244353; #include<atcoder/all> using namespace atcoder; using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n;cin>>n; vector<ll> A(n); rep(i,n) cin>>A[i]; vector<bitset<12>> B(n); rep(i,n){ B[i] = bitset<12>(A[i]); } dsu uf(n); rep(i,12){ vector<ll> v; rep(j,n){ if(B[j][i]) v.push_back(j); } if(v.size()>1){ rep(j,(int)v.size()-1){ uf.merge(v[j],v[j+1]); } } } vector<pair<ll,ll>> G; map<ll,vector<int>> mp; for(auto g:uf.groups()){ ll x=0; mp[uf.leader(g[0])]=g; for(auto i:g) x|=A[i]; G.push_back({x, uf.leader(g[0])}); } G.push_back({0, -1}); sort(all(G)); vector<ll> G1; for(auto p:G) G1.push_back(p.first); ll m = G.size(); rep(i,m-1){ G1[i+1]+=G1[i]; } ll sum=G1.back(); auto it=lower_bound(all(G1), G1.back()/2); vector<char> Ans(n,'W'); ll q; if(*it*(sum-*it)>*(it-1)*(sum-*(it-1))){ q=it-G1.begin()+1; }else{ q=it-G1.begin(); } rep(i,q){ for(auto j:mp[G[i].second]){ Ans[j]='B'; } } cout<<max(*it*(sum-*it),*(it-1)*(sum-*(it-1)))<<endl; cout<<string(all(Ans))<<endl; }