結果
問題 |
No.3219 Ruler to Maximize
|
ユーザー |
|
提出日時 | 2025-08-01 22:14:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,354 bytes |
コンパイル時間 | 737 ms |
コンパイル使用メモリ | 88,112 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-08-01 22:14:34 |
合計ジャッジ時間 | 3,494 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 16 |
ソースコード
#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; } if (W == mask) return 0; else 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; }