Codeforces Round #443 (Div. 2), problem: (C) Short Program Solution In C/C++

#include <iostream>
using namespace std;

const int maxn = 5e5;
int n, x, a = 0, b = 1023, y[3];
char c;

int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> c >> x;
if (c == ‘&’)
{
a &= x;
b &= x;
}
else if (c == ‘|’)
{
a |= x;
b |= x;
}
else
{
a ^= x;
b ^= x;
}
}
for (int i = 0; i < 10; i++)
{
if ((a & (1 << i)) && (b & (1 << i)))
{
y[0] += 1 << i;
y[1] += 1 << i;
}
else if (a & (1 << i))
{
y[0] += 1 << i;
y[2] += 1 << i;
}
else if (b & (1 << i))
{
y[0] += 1 << i;
}
}
cout << 3 << “\n& ” << y[0] << “\n| ” << y[1] << “\n^ ” << y[2];
}

Advertisement

spot_img

Is Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

Stop Buying Cheap Alternatives...

📢 As an Amazon Associate, I earn from qualifying...

Movies at 30,000 feet:...

For decades, Hollywood has gauged its global cultural footprint...

7 Reasons This Viral...

📢 As an Amazon Associate, I earn from qualifying...

How Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

APTEXPO 2026 Spotlights AI-Driven...

The Future of Fashion: APTEXPO 2026 Set to Convene...

Is Viral Kitchen Gadgets Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Movies at 30,000 feet: Hollywood’s high-flying market

For decades, Hollywood has gauged its global cultural footprint through traditional theatrical ticket sales and home entertainment revenue. However, a parallel exhibition market cruising...

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

How Viral Kitchen Gadgets Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

APTEXPO 2026 Spotlights AI-Driven Supply Chains, Sustainable Materials, and Asian Fashion Brands

The Future of Fashion: APTEXPO 2026 Set to Convene in SingaporeThe global textile and apparel industry is standing at the precipice of a monumental...

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Jaishankar meets senior Japanese leaders; discusses deeper strategic, economic ties

In a significant step forward for Indo-Pacific diplomacy, External Affairs Minister S. Jaishankar met with senior Japanese leaders in Tokyo to deliberate on enhancing...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....