답안 #545904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545904 2022-04-05T16:05:46 Z rainboy 괄호 문자열 (CEOI16_match) C
0 / 100
8 ms 468 KB
/* upsolve after reading analysis */
#include <stdio.h>
#include <string.h>

#define N	1234567

int sum(int n, int a, int b) {
	int m = n * 2 + 1, d = (b - a + m) % m;

	if (n % 2 == 0 && d % 2 == 0 && d < m - 1)
		return (a + d / 2) % m;
	if (n % 2 == 1 && (m - d) % 2 == 0 && d > 1)
		return (b + (m - d) / 2) % m;
	if (d == 1 || d == m - 1)
		return a;
	if (d == (n + 3) % m || d == (n - 1 + m) % m)
		return (a - n + m) % m;
	if (d == (n - 3 + m) % m || d == (n + 5) % m)
		return (b - n - 1 + m) % m;
	return -1;
}

int main() {
	int t, r;

	scanf("%d%d", &t, &r);
	if (r != 3)
		while (t--) {
			static int aa[N];
			static char used[N * 2 + 1];
			int n, m, i, s, a, b;

			scanf("%d", &n), m = n * 2 + 1;
			s = 0;
			for (i = 0; i < n; i++) {
				scanf("%d", &aa[i]);
				s = (s + aa[i]) % m;
			}
			memset(used, 0, m * sizeof *used);
			for (i = 0; i < n; i++)
				used[aa[i] = (aa[i] - s + m) % m] = 1;
			a = -1, b = -1;
			for (i = 1; i < n; i++)
				if (used[i] && used[m - i]) {
					if (n % 2 == 0)
						a = (m - i + s) % m, b = (i + s) % m;
					else
						a = (i + s) % m, b = (m - i + s) % m;
					break;
				}
			if (a == -1 && b == -1) {
				if (used[0] && used[1])
					a = (0 + s) % m, b = (1 + s) % m;
				else if (used[0] && used[m - 1])
					a = (0 + s) % m, b = (m - 1 + s) % m;
				else if (used[n] && used[2])
					a = (n + s) % m, b = (2 + s) % m;
				else if (used[n] && used[m - 2])
					a = (n + s) % m, b = (m - 2 + s) % m;
				else if (used[4] && used[n + 1])
					a = (4 + s) % m, b = (n + 1 + s) % m;
				else if (used[m - 4] && used[n + 1])
					a = (m - 4 + s) % m, b = (n + 1 + s) % m;
			}
			printf("%d %d\n", a, b);
		}
	else
		while (t--) {
			int n, m, a, b, c, d;

			scanf("%d%d%d%d%d", &n, &a, &b, &c, &d), m = n * 2 + 1;
			printf("%d\n", (m * 2 - sum(n, a, b) - sum(n, c, d)) % m);
		}
	return 0;
}

Compilation message

match.c: In function 'main':
match.c:26:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%d", &t, &r);
      |  ^~~~~~~~~~~~~~~~~~~~~
match.c:33:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |    scanf("%d", &n), m = n * 2 + 1;
      |    ^~~~~~~~~~~~~~~
match.c:36:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d", &aa[i]);
      |     ^~~~~~~~~~~~~~~~~~~
match.c:71:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d), m = n * 2 + 1;
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -