結果

問題 No.3219 Ruler to Maximize
ユーザー eve__fuyuki
提出日時 2025-08-14 17:42:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 195,636 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-08-14 17:42:32
合計ジャッジ時間 4,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}

int main() {
	fast_io();
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int b = 0, w = 0;
	for (int msk = 0; msk < 4096; msk++) {
		bool is_ok = true;
		int ww = 0;
		int bb = 0;
		for (int j = 0; j < n; j++) {
			if ((msk & a[j]) == 0) {
				ww = ww | a[j];
				continue;
			}
			if ((a[j] | msk) != msk) {
				is_ok = false;
				break;
			}
			bb = bb | a[j];
		}
		if (is_ok && b * w < bb * ww) {
			b = bb;
			w = ww;
		}
	}
	string ans(n, 'W');
	for (int j = 0; j < n; j++) {
		if ((b & a[j]) != 0) {
			ans[j] = 'B';
		}
	}
	cout << b * w << endl;
	cout << ans << endl;
}
0