Submission #57107289


Source Code Expand

Copy
#include <stdio.h>
#include <limits.h>
int add0(int* carry, int a, int b) {
*carry = a + b >= 2;
return a != b;
}
int add1(int* carry_out, int a, int b, int c) {
*carry_out = (a && b) || (b && c) || (c && a);
a ^= b ^ c;
return +a;
}
int add2(int* carry_out, int a, int b, int c) {
int ab, bc, ca;
ab = a; ab -= -b;
bc = 0;
if (b) bc--;
if (c) --bc;
ca = c; ca += a;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <limits.h>

int add0(int* carry, int a, int b) {
	*carry = a + b >= 2;
	return a != b;
}

int add1(int* carry_out, int a, int b, int c) {
	*carry_out = (a && b) || (b && c) || (c && a);
	a ^= b ^ c;
	return +a;
}

int add2(int* carry_out, int a, int b, int c) {
	int ab, bc, ca;
	ab = a; ab -= -b;
	bc = 0;
	if (b) bc--;
	if (c) --bc;
	ca = c; ca += a;
	*carry_out = !!((ab == 2) + (bc <= -2) + (1 < ca));
	return (a + b + c) % 2;
}

struct add3_ret {
	int result;
	int carry;
};

struct add3_ret add3(int a, int b, int c) {
	int ab, bc, ca;
	ab = a; ab *= b;
	bc = ~(~b | ~c);
	ca = c; ca <<= a;
	return (struct add3_ret){ (a != b) - c ? 1 : 0, ab || bc || (ca & 2) };
}

int main(void) {
	int a, b;
	int a_bits[7], b_bits[7], ans_bits[8];
	int i, carry;
	struct add3_ret ret;
	int ans = 0;
	if (scanf("%d%d", &a, &b) != 2) return 1;
	a_bits[0] = ((unsigned int)a << (sizeof(unsigned int) * CHAR_BIT - 1)) > 0;
	a_bits[1] = a / 2; a_bits[1] %= 2;
	a_bits[2] = a >> 2; a_bits[2] &= 1;
	a_bits[3] = a % 16; a_bits[3] /= 8;
	a_bits[4] = a % 32; a_bits[4] >>= 4;
	a_bits[5] = (a >> 5) & 1;
	a_bits[6] = a >> 6;
	for (i = 0; i < 7; i++) {
		b_bits[i] = (b >> i) & 1;
	}

	ans_bits[0] = add0(&carry, a_bits[0], b_bits[0]);
	ans_bits[1] = add1(&carry, a_bits[1], b_bits[1], carry);
	ans_bits[2] = add2(&carry, a_bits[2], b_bits[2], carry);
	ret = add3(a_bits[3], b_bits[3], carry);
	ans_bits[3] = (&ret)->result;
	ret = add3(a_bits[4], b_bits[4], ret.carry);
	ans_bits[4] = ret.result;
	ans_bits[5] = add2(&carry, a_bits[5], b_bits[5], ret.carry);
	ans_bits[6] = add1(&ans_bits[7], a_bits[6], b_bits[6], carry);

	for (i = 0, ans = 0; i < 8; ++i) {
		ans |= ans_bits[i] << i;
	}
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task EX5 - 1.05
User mikecat
Language C (gcc 12.2.0)
Score 100
Code Size 1808 Byte
Status AC
Exec Time 0 ms
Memory 1724 KB

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 6
Set Name Test Cases
all sample01.txt, sample02.txt, test01.txt, test02.txt, test03.txt, test04.txt
Case Name Status Exec Time Memory
sample01.txt AC 0 ms 1592 KB
sample02.txt AC 0 ms 1568 KB
test01.txt AC 0 ms 1620 KB
test02.txt AC 0 ms 1724 KB
test03.txt AC 0 ms 1628 KB
test04.txt AC 0 ms 1624 KB


2024-08-25 (Sun)
09:31:44 +09:00