From 554ad47f09974f0131df285fda8ea50a1fdad8f5 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 11 Dec 2023 15:14:47 +0100 Subject: Initial commit, some solutions --- 2023/06/6a.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2023/06/6b.txt | 1 + 2023/06/in.txt | 2 ++ 2023/06/in2.txt | 2 ++ 4 files changed, 49 insertions(+) create mode 100644 2023/06/6a.c create mode 100644 2023/06/6b.txt create mode 100644 2023/06/in.txt create mode 100644 2023/06/in2.txt (limited to '2023/06') diff --git a/2023/06/6a.c b/2023/06/6a.c new file mode 100644 index 0000000..4ce8fd1 --- /dev/null +++ b/2023/06/6a.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include + +#define N 100000 + +#define MIN(a, b) ((a)<(b)?(a):(b)) +#define MAX(a, b) ((a)>(b)?(a):(b)) + +bool isnum(char c) { return c >= '0' && c <= '9'; } + +int64_t readl(int64_t nums[], char *buf) { + int64_t i; + for (i = 0; *buf; buf++) { + if (!isnum(*buf)) continue; + nums[i++] = atoll(buf); + while (isnum(*buf)) buf++; + } + return i; +} + +int main() { + char line[N], clean[N]; + int64_t i, n, p, D, x1, x2, t[N], d[N]; + + n = readl(t, fgets(line, N, stdin)); + readl(d, fgets(line, N, stdin)); + + p = 1; + for (i = 0; i < n; i++) { + D = t[i]*t[i] - 4*d[i]; + if (D < 0) p = 1; + double sq = sqrt(D); + x1 = (int64_t)floor((t[i] - sq)/2) + 1; + x2 = (int64_t)ceil((t[i] + sq)/2) - 1; + p *= x2 - x1 + 1; + } + + printf("%" PRId64 "\n", p); + return 0; +} diff --git a/2023/06/6b.txt b/2023/06/6b.txt new file mode 100644 index 0000000..3d9fcf8 --- /dev/null +++ b/2023/06/6b.txt @@ -0,0 +1 @@ +Just use 6a and modify the input file manually diff --git a/2023/06/in.txt b/2023/06/in.txt new file mode 100644 index 0000000..db24621 --- /dev/null +++ b/2023/06/in.txt @@ -0,0 +1,2 @@ +Time: 41 96 88 94 +Distance: 214 1789 1127 1055 diff --git a/2023/06/in2.txt b/2023/06/in2.txt new file mode 100644 index 0000000..000bcf9 --- /dev/null +++ b/2023/06/in2.txt @@ -0,0 +1,2 @@ +Time: 41968894 +Distance: 214178911271055 -- cgit v1.3