From 924cc71d24dfb27586b04d37491f1572afd92f9e Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Fri, 14 Aug 2026 19:40:23 +0800 Subject: [PATCH] new file: P2114.cpp --- P2114.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 P2114.cpp diff --git a/P2114.cpp b/P2114.cpp new file mode 100644 index 0000000..8a681a4 --- /dev/null +++ b/P2114.cpp @@ -0,0 +1,43 @@ +// 998 +#include +using namespace std; +int n, m, ans, t[100005], op[100005]; +char str[4]; +bool calc(bool x, int j) +{ + for (int i = 0; i < n; i++) + if (op[i] == 1) + x |= t[i] >> j & 1; + else if (op[i] == 2) + x ^= t[i] >> j & 1; + else + x &= t[i] >> j & 1; + return x; +} +int main() +{ + scanf("%d %d", &n, &m); + for (int i = 0; i < n; i++) + { + scanf("\n%s %d", str, t + i); + if (str[0] == 'O') + op[i] = 1; + else if (str[0] == 'X') + op[i] = 2; + else + op[i] = 3; + } + for (int i = 29; ~i; i--) + if (1 << i <= m) + { + bool x = calc(0, i), y = calc(1, i); + if (x >= y) + ans |= x << i; + else + ans |= y << i, m -= 1 << i; + } + else + ans |= calc(0, i) << i; + printf("%d\n", ans); + return 0; +} \ No newline at end of file