結果
問題 |
No.3219 Ruler to Maximize
|
ユーザー |
|
提出日時 | 2025-08-01 22:17:01 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,323 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 88,200 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-01 22:17:04 |
合計ジャッジ時間 | 2,283 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include <iostream> #include <cstdint> #include <vector> static inline constexpr uint_fast32_t check(const uint_fast32_t N, const std::vector<uint_fast32_t>& A, const uint_fast32_t mask) noexcept { uint_fast32_t W = 0, B = 0; for (uint_fast32_t i = 0; i != N; ++i) { if ((A[i] & mask) == A[i]) W |= A[i]; else if ((A[i] & mask) == 0) B |= A[i]; else return 0; } return W * B; } static inline constexpr std::pair<uint_fast32_t, std::string> solve(const uint_fast32_t N, const std::vector<uint_fast32_t>& A) noexcept { uint_fast32_t ans = 0, best_mask = 0; for (uint_fast32_t i = 0; i != 4096; ++i) { const uint_fast32_t result = check(N, A, i); if (ans < result) ans = result, best_mask = i; } std::string S; S.reserve(N); for (uint_fast32_t i = 0; i != N; ++i) { if ((A[i] & best_mask) == 0) S.push_back('B'); else S.push_back('W'); } return std::make_pair<uint_fast32_t, std::string>(std::move(ans), std::move(S)); } static inline void output(const std::pair<uint_fast32_t, std::string>& ans) noexcept { std::cout << ans.first << '\n' << ans.second << '\n'; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t N, i; std::cin >> N; std::vector<uint_fast32_t> A(N); for (i = 0; i != N; ++i) std::cin >> A[i]; output(solve(N, A)); return 0; }