結果
問題 |
No.3219 Ruler to Maximize
|
ユーザー |
|
提出日時 | 2025-08-01 22:08:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 1,812 ms |
コンパイル使用メモリ | 195,752 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-01 22:08:19 |
合計ジャッジ時間 | 3,583 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int N = 200005; const int INF = 0x3f3f3f3f; int a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int mx = 0; for (int i = 0; i < n; i++) { cin >> a[i]; mx = max(mx, a[i]); } int k = __lg(mx) + 1; int max1 = (1 << k) - 1; ll ans = 0; int u = 0; for (int mask = 0; mask <= max1; mask++) { ll m1 = 0, m2 = 0; bool ok = 1; for (int i = 0; i < n; i++) { bool fw = !(a[i] & (max1 ^ mask)); bool fb = !(a[i] & mask); if (!fw && !fb) { ok = 0; break; } if (fw) { m1 |= a[i]; } else { m2 |= a[i]; } } if (!ok) continue; if (m1 * m2 > ans) { ans = m1 * m2; u = mask; } } string res; ll m1 = 0, m2 = 0; for (int i = 0; i < n; i++) { bool fw = !(a[i] & (max1 ^ u)); if (fw) { res.push_back('B'); m1 |= a[i]; } else { res.push_back('W'); m2 |= a[i]; } } cout << ans << "\n"; cout << res << "\n"; return 0; }