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

Compiler report

input/code.cpp: In function 'uint64_t test(uint64_t, uint64_t, uint64_t)':
input/code.cpp:35:23: warning: unused variable 'l' [-Wunused-variable]
  uint64_t x, y, m, r, 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));
	}

	/*l = (((n + 1) - (x > y ? x : y)) > (x < y ? x : y) ? (x < y ? x : y) : (x > y ? x : y));

	printf("%ld %ld : %ld\n", (x > y ? x : y), (n + 1) - (x > y ? x : y), l);
	printf("%ld %ld\n", (n/2)+1, (n/2)+1 > l ? l : ((n + 1) - l));*/


	return 0;
}

uint64_t test(uint64_t X, uint64_t Y, uint64_t n) {
	uint64_t x, y, m, r, l;

	x = 1;
	y = 1;
	m = n;
	r = 1;

	while((x != X) || (y != Y)) {
		for(; y < m; y++, r++) {
			if(x == X && y == Y) {
				goto end_loop;
			}
		}

		for(; x < m; x++, r++) {
			if(x == X && y == Y) {
				goto end_loop;
			}
		}

		for(; y > OPPOSITE(m, n); y--, r++) {
			if(x == X && y == Y) {
				goto end_loop;
			}
		}

		m--;

		for(; x > OPPOSITE(m, n); x--, r++) {
			if(x == X && y == Y) {
				goto end_loop;
			}
		}
	}
end_loop:
	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)