CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:victor05
Submission time:2021-10-10 12:34:33
Language:C++11
Status:READY
Result:35
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1details
#2ACCEPTED0.01 s2details
#3--3details

Compiler report

input/code.cpp: In function 'uint64_t test(uint64_t, uint64_t, uint64_t)':
input/code.cpp:29:17: warning: unused variable 'T' [-Wunused-variable]
  uint64_t r, l, T, d, i, j, L;
                 ^
input/code.cpp: In function 'int main()':
input/code.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%ld %ld", &n, &t);
  ~~~~~^~~~~~~~~~~~~~~~~~~
input/code.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%ld %ld", &y, &x);
   ~~~~~^~~~~~~~~~~~~~~~~~~

Code

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define OPPOSITE(x, y)		(y - (x-1))

uint64_t test(uint64_t x, uint64_t y, uint64_t n);

int main(void) {
	uint64_t n, t, x, y, i, *r;

	scanf("%ld %ld", &n, &t);

	r = (uint64_t *)malloc(sizeof(uint64_t) * t);

	for(i = 0; i < t; i++) {
		scanf("%ld %ld", &y, &x);
		*(r + i) = test(x, y, n);
	}

	for(i = 0; i < t; i++) {
		printf("%ld\n", *(r + i));
	}

	return 0;
}

uint64_t test(uint64_t x, uint64_t y, uint64_t n) {
	uint64_t r, l, T, d, i, j, L;

	l = ((x < y) ? ((OPPOSITE(y, n) < x) ? OPPOSITE(y, n) : x) : ((OPPOSITE(x, n) < y) ? OPPOSITE(x, n) : y));
	d = (x == l) ? 0 : ((OPPOSITE(x, n) == l) ? 2 : ((y == l) ? 3 : 1));


	if(l != 1) {
		r = 3 * (n - 1);

		i = n - 2;
		for(L = l; L > 1; L--) {
			for(j = 0; j < 2; j++) {
				r += i;
				if(j == d && L == 2) {
					goto end_loop;
				}
			}

			i--;

			for(j = 2; j < 4; j++) {
				r += i;
				if(j == d && L == 2) {
					goto end_loop;
				}
			}

			i--;
		}
end_loop:
		r += (d == 0) ? (y - (l - 2)) : ((d == 1) ? (x - (l - 1)) : ((d == 2) ? (n - (y-1) - (l - 1)) : (n - (x-1) - (l - 1)))); 
	}
	else {
		r = d * (n - 1);
		r += (d == 0) ? y : ((d == 1) ? x : ((d == 2) ? (n - (y-1)) : (n - (x-1)))); 
	}



	return r;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10 100
1 1
1 2
1 3
1 4
...

correct output
1
36
35
34
33
...

user output
1
36
35
34
33
...

Test 2

Group: 2

Verdict: ACCEPTED

input
1000 1000
371 263
915 322
946 880
53 738
...

correct output
773533
312166
206053
200080
593922
...

user output
773533
312166
206053
200080
593922
...

Test 3

Group: 3

Verdict:

input
1000000000 1000
177757853 827347032
409613589 419171337
739269360 256524697
328695530 896842209
...

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
(empty)