summaryrefslogtreecommitdiffstats
path: root/šola
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-03-24 12:42:20 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-03-24 12:42:20 +0100
commitc4fbb0ad7fe9e3f5035a7f431b6887427556690c (patch)
tree8853b11eb58235dab45477a27d25eb273d7e1668 /šola
parentpiracy (diff)
downloadr-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar.gz
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar.bz2
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar.lz
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar.xz
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.tar.zst
r-c4fbb0ad7fe9e3f5035a7f431b6887427556690c.zip
Diffstat (limited to 'šola')
-rw-r--r--šola/p2/dn/DN04a_63230317.c30
-rw-r--r--šola/p2/dn/DN04b_63230317.c39
2 files changed, 69 insertions, 0 deletions
diff --git a/šola/p2/dn/DN04a_63230317.c b/šola/p2/dn/DN04a_63230317.c
new file mode 100644
index 0000000..9c1c1b1
--- /dev/null
+++ b/šola/p2/dn/DN04a_63230317.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdbool.h>
+int main (void) {
+ int n;
+ scanf("%d", &n);
+ int a[2*n];
+ unsigned int lsum = 0;
+ unsigned int rsum = 0;
+ for (int i = 0; i < 2*n; i++)
+ scanf("%d", &a[i]);
+ for (int k = 0;; k++) {
+ if (lsum == rsum) {
+ bool pravilno = true;
+ for (int j = 0; j < n; j++) {
+ // fprintf(stderr, "%d\t%d\t%d\t%d\n", j, a[j], (n+(n-k+j) % n), a[(n+(n-k+j) % n)]);
+ if (a[j] == a[n+(n-k+j) % n])
+ continue;
+ pravilno = false;
+ break;
+ }
+ if (pravilno) {
+ printf("%d\n", k);
+ break;
+ }
+ }
+ lsum += a[k];
+ rsum += a[2*n-1-k];
+
+ }
+}
diff --git a/šola/p2/dn/DN04b_63230317.c b/šola/p2/dn/DN04b_63230317.c
new file mode 100644
index 0000000..105890a
--- /dev/null
+++ b/šola/p2/dn/DN04b_63230317.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdbool.h>
+int main (void) {
+ int n, k, s = 0;
+ scanf("%d %d", &n, &k);
+ int a[n];
+ for (int i = 0; i < n; i++)
+ scanf("%d", &a[i]);
+ int d, l = n-1;
+ for (int i = 0; i < n-1; i++)
+ if (2*a[i] <= k && 2*a[i+1] > k)
+ l = i;
+ d = l;
+ fprintf(stderr, "l je %d, d je %d\n", l, d);
+ do {
+ if (a[l]+a[d] == k) {
+ int lc = l;
+ int dc = d;
+ int add = 0;
+ while (lc >= 0 && a[lc] == a[l])
+ lc--;
+ while (dc <= n-1 && a[dc] == a[d])
+ dc++;
+ if (a[l] == a[d]) // (dc-lc) choose 2
+ add = ((dc-lc-1)*n)/2;
+ else
+ add = (d-dc+1)*(lc-l+1);
+ fprintf(stderr, "l=%d, d=%d, a[l]=%d, a[d]=%d, lc=%d, dc=%d, add=%d\n", l, d, a[l], a[d], lc, dc, add);
+ l = lc;
+ d = dc;
+ s += add;
+ }
+ if (l-1 >= 0)
+ l--;
+ if (d+1 < n)
+ d++;
+ } while (d < n-1 || l > 0);
+ printf("%d\n", s);
+}