# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056220 | Soysauce | Alice, Bob, and Circuit (APIO23_abc) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <unordered_map>
#include <vector>
#include <cstring>
const int MOD = 65536;
int alice(const int n, const char names[][5], const unsigned short numbers[], bool outputs_alice[]) {
// Simple encoding: We will use a naive approach for the binary string from Alice
for (int i = 0; i < n; ++i) {
// Output the least significant bits of the favorite numbers
outputs_alice[i] = (numbers[i] & 1); // Just an example: taking the LSB of each number
}
return n; // Return the length of the binary string
}
int bob(const int m, const char senders[][5], const char recipients[][5], bool outputs_bob[]) {
// Simple encoding: Use a simple approach for encoding sender-recipient pairs
for (int i = 0; i < m; ++i) {
// Example: encode if the first letter of sender and recipient are the same
outputs_bob[i] = (senders[i][0] == recipients[i][0]);
}
return m; // Return the length of the binary string
}
int circuit(const int la, const int lb, int operations[], int operands[][2], int outputs_circuit[][16]) {
// Simple circuit: We'll perform a couple of operations
int gate_count = la + lb;
// Perform an AND operation between the first bit from Alice and the first bit from Bob
operations[gate_count] = 8; // AND operation
operands[gate_count][0] = 0; // First bit from Alice
operands[gate_count][1] = la; // First bit from Bob
gate_count++;
// Perform an OR operation between the result and the second bit from Alice
operations[gate_count] = 14; // OR operation
operands[gate_count][0] = 0; // First bit from Alice
operands[gate_count][1] = gate_count - 1; // Previous gate
gate_count++;
// Output the result to the outputs_circuit
for (int i = 0; i < la; ++i) {
for (int j = 0; j < 16; ++j) {
outputs_circuit[i][j] = operands[gate_count - 1][j % 2];
}
}
return gate_count; // Return the number of gates used
}
// Sample usage
int main() {
// Sample data
int n = 3;
const char names[3][5] = {"alic", "bob", "circ"};
unsigned short numbers[3] = {10000, 20000, 30000};
bool outputs_alice[10] = {0};
int m = 5;
const char senders[5][5] = {"alic", "bob", "bob", "circ", "circ"};
const char recipients[5][5] = {"circ", "circ", "alic", "circ", "circ"};
bool outputs_bob[10] = {0};
int operations[100] = {0};
int operands[100][2] = {0};
int outputs_circuit[3][16] = {0};
// Call the functions
int la = alice(n, names, numbers, outputs_alice);
int lb = bob(m, senders, recipients, outputs_bob);
int gate_count = circuit(la, lb, operations, operands, outputs_circuit);
// Output the results
std::cout << "Alice's output: ";
for (int i = 0; i < la; ++i) {
std::cout << outputs_alice[i];
}
std::cout << std::endl;
std::cout << "Bob's output: ";
for (int i = 0; i < lb; ++i) {
std::cout << outputs_bob[i];
}
std::cout << std::endl;
std::cout << "Circuit's output: " << std::endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 16; ++j) {
std::cout << outputs_circuit[i][j];
}
std::cout << std::endl;
}
return 0;
}