求助!有大佬帮忙看看起床困难综合症吗

# 读取输入
n, m = map(int, input().split())
doors = []

# 记录防御门的操作和参数
for _ in range(n):
    op, t = input().split()
    doors.append((op, int(t)))

# 初始化最大攻击力
attack = 0
result = 0
def check(result):
    for op, t in doors:
        if op == "AND":
            result &= t
        elif op == "OR":
            result |= t
        elif op == "XOR":
            result ^= t
    return result
if n == 0:
    print(m)
    exit(0)
# 从高位到低位尝试
for bit in range(m.bit_length() - 1, -1, -1):
    # 当前位假设为 1
    temp_attack = attack | (1 << bit)
    if temp_attack > m:
        continue
    temp_result = check(temp_attack)

    # 如果假设的当前位为 1 不超过 `m` 且使结果更优,保留该位
    if temp_result >= result:
        attack += temp_attack

# 模拟一次完整攻击后的结果
result = check(attack)

# 输出结果
print(result)

全部评论
打牛客求职答疑中心的tag可以召唤牛可乐,亲测ai有时候解题蛮好用佬下次可以试试哈哈
1 回复 分享
发布于 01-12 16:12 北京
@牛客求职答疑中心
点赞 回复 分享
发布于 01-12 20:42 广东

相关推荐

点赞 评论 收藏
分享
投递腾讯等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务