Submission #66392154


Source Code Expand

#include <stdio.h>
#include <inttypes.h>

int N;
int A[312345];

int main(void) {
	int i;
	uint64_t ans = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
		ans += A[i];
	}
	ans *= ans;
	for (i = 0; i < N; i++) {
		ans -= (uint64_t)A[i] * A[i];
	}
	printf("%" PRIu64 "\n", ans / 2);
	return 0;
}

/*

A_1 * A_1 + ... + A_1 * A_N + A_2 * A_1 + ... + A_N * A_N
= A_1 * (A_1 + ... + A_N) + ... + A_N * (A_1 + ... + A_N)
= (A_1 + ... + A_N) * (A_1 + ... + A_N)

これから A_i * A_i を引いて、半分にすればよい

*/

Submission Info

Submission Time
Task C - Sum of Product
User mikecat
Language C (gcc 12.2.0)
Score 300
Code Size 615 Byte
Status AC
Exec Time 22 ms
Memory 2904 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 22
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 0 ms 1720 KiB
00_sample_01.txt AC 0 ms 1616 KiB
00_sample_02.txt AC 0 ms 1620 KiB
01_random_00.txt AC 9 ms 2204 KiB
01_random_01.txt AC 16 ms 2628 KiB
01_random_02.txt AC 20 ms 2716 KiB
01_random_03.txt AC 10 ms 2168 KiB
01_random_04.txt AC 16 ms 2604 KiB
01_random_05.txt AC 22 ms 2904 KiB
01_random_06.txt AC 21 ms 2760 KiB
01_random_07.txt AC 21 ms 2888 KiB
01_random_08.txt AC 21 ms 2816 KiB
01_random_09.txt AC 21 ms 2788 KiB
01_random_10.txt AC 21 ms 2884 KiB
01_random_11.txt AC 22 ms 2796 KiB
01_random_12.txt AC 21 ms 2796 KiB
01_random_13.txt AC 21 ms 2872 KiB
01_random_14.txt AC 21 ms 2900 KiB
02_handmade_00.txt AC 0 ms 1620 KiB
02_handmade_01.txt AC 0 ms 1612 KiB
02_handmade_02.txt AC 13 ms 2784 KiB
02_handmade_03.txt AC 16 ms 2796 KiB