Skip to content

Commit 08c3d60

Browse files
committed
ABC169-B: C version
1 parent 8b3f7f7 commit 08c3d60

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

abc/abc169-b/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdbool.h>
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
int main(void)
5+
{
6+
int n;
7+
scanf("%d", &n);
8+
unsigned long long *input = calloc(n, sizeof(unsigned long long));
9+
for (int i = 0; i < n; ++i) {
10+
scanf("%llu", &input[i]);
11+
}
12+
unsigned long long p = 1;
13+
bool overflow = false;
14+
for (int i = 0; i < n; ++i) {
15+
unsigned long long a = p, b = input[i];
16+
if (b == 0ull) {
17+
puts("0");
18+
return 0;
19+
}
20+
unsigned long long c = a * b;
21+
if (c > 1000000000000000000ull || c / a != b || c / b != a) {
22+
overflow = true;
23+
} else {
24+
p = c;
25+
}
26+
}
27+
if (overflow) {
28+
puts("-1");
29+
} else {
30+
printf("%llu\n", p);
31+
}
32+
}

0 commit comments

Comments
 (0)