답안 #491651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491651 2021-12-03T17:17:36 Z valerikk Squirrel (RMI18_squirrel) C++17
50 / 100
4700 ms 131312 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

const int MAX_FRACTAL_SIZE = 1024;
const int GCD_TABLE_SIZE = 5000;

std::vector<std::pair<int, int>> jumps[MAX_FRACTAL_SIZE + 1];

void build_jumps() {
	jumps[1] = {{1, 0}};
	for (int fractal_size = 2; fractal_size <= MAX_FRACTAL_SIZE; fractal_size *= 2) {
		for (int i = 1; i <= fractal_size; ++i) {
			jumps[fractal_size].emplace_back(i, 0);
		}
		for (int i = 1; i <= fractal_size / 2; ++i) {
			jumps[fractal_size].emplace_back(fractal_size + i, i);
		}
		for (int i = 1; i <= fractal_size / 2; ++i) {
			jumps[fractal_size].emplace_back(fractal_size + i, -i);
		}
		for (const auto &[x, y] : jumps[fractal_size / 2]) {
			jumps[fractal_size].emplace_back(fractal_size + fractal_size / 2 + x, fractal_size / 2 + y);
			jumps[fractal_size].emplace_back(fractal_size + fractal_size / 2 + x, -fractal_size / 2 + y);
			jumps[fractal_size].emplace_back(fractal_size + fractal_size / 2 + y, fractal_size / 2 + x);
			jumps[fractal_size].emplace_back(fractal_size + fractal_size / 2 - y, -fractal_size / 2 - x);
		}
	}
}

int gcd_table[GCD_TABLE_SIZE + 1][GCD_TABLE_SIZE + 1];

void build_gcd_table() {
	for (int a = 0; a <= GCD_TABLE_SIZE; ++a) {
		for (int b = a; b <= GCD_TABLE_SIZE; ++b) {
			gcd_table[a][b] = gcd_table[b][a] = (a == 0 || b == 0 ? a + b : gcd_table[b - a][a]);
		}
	}
}

int gcd(int a, int b) {
	while (b != 0 && b > GCD_TABLE_SIZE) {
		a %= b;
		std::swap(a, b);
	}
	return (b == 0 ? a : gcd_table[a % b][b]);
}

int main() {
	build_jumps();
	build_gcd_table();

	int N, M, F;
	scanf("%d%d%d", &N, &M, &F);
	int answer = 0;
	while (F--) {
		int x, y, fractal_size;
		scanf("%d%d%d", &x, &y, &fractal_size);
		--x;
		--y;
		answer += gcd(x, y) == 1;
		for (const auto &[dx, dy] : jumps[fractal_size]) {
			answer += gcd(x - dx, y - dy) == 1;
		}
	}
	printf("%d\n", answer);
	return 0;
}

Compilation message

squirrel.cpp: In function 'int main()':
squirrel.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d%d", &N, &M, &F);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
squirrel.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d%d%d", &x, &y, &fractal_size);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 322 ms 131248 KB Output is correct
2 Correct 330 ms 131100 KB Output is correct
3 Correct 1006 ms 131156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1752 ms 131256 KB Output is correct
2 Correct 1651 ms 131076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2520 ms 131068 KB Output is correct
2 Correct 2677 ms 131084 KB Output is correct
3 Correct 2771 ms 131208 KB Output is correct
4 Correct 2884 ms 131156 KB Output is correct
5 Correct 3177 ms 131312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4785 ms 131132 KB Time limit exceeded
2 Execution timed out 4797 ms 131176 KB Time limit exceeded
3 Execution timed out 4802 ms 131132 KB Time limit exceeded
4 Execution timed out 4806 ms 131080 KB Time limit exceeded
5 Execution timed out 4798 ms 131260 KB Time limit exceeded
6 Execution timed out 4793 ms 131176 KB Time limit exceeded
7 Execution timed out 4806 ms 131196 KB Time limit exceeded
8 Execution timed out 4809 ms 131200 KB Time limit exceeded
9 Execution timed out 4802 ms 131176 KB Time limit exceeded
10 Execution timed out 4788 ms 131192 KB Time limit exceeded