제출 #491655

#제출 시각아이디문제언어결과실행 시간메모리
491655valerikkSquirrel (RMI18_squirrel)C++17
100 / 100
4331 ms131444 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

const int MAX_FRACTAL_SIZE = 1024;
const int MAX_NUMBER = 10000;

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

bool visible[MAX_NUMBER + 1][MAX_NUMBER + 1];

bool is_visible(int a, int b) {
	if (!(a & 1) && !(b & 1)) {
		return false;
	}
	while (b != 0 && b > MAX_NUMBER) {
		a %= b;
		std::swap(a, b);
	}
	return b == 0 ? a <= 1 : visible[a % b][b];
}

int main() {
	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);
		}
	}

	for (int a = 0; a <= MAX_NUMBER; ++a) {
		for (int b = a; b <= MAX_NUMBER; ++b) {
			visible[a][b] = visible[b][a] = (a == 0 ? b <= 1 : visible[a][b - a]);
		}
	}

	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 += is_visible(x, y);
		for (const auto &[dx, dy] : jumps[fractal_size]) {
			answer += is_visible(x - dx, y - dy);
		}
	}
	printf("%d\n", answer);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

squirrel.cpp: In function 'int main()':
squirrel.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d%d", &N, &M, &F);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
squirrel.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d%d", &x, &y, &fractal_size);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...