답안 #406427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406427 2021-05-17T15:02:29 Z atoiz Nicelines (RMI20_nicelines) C++14
34 / 100
232 ms 1784 KB
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>

#include "nice_lines.h"

const int X = 100000;

bool zero(long double x) { return std::abs(x) < 100; }
bool equals(long double x, long double y) { 
	return zero(x - y); 
}

void add(int64_t Y, std::vector<int> &A, std::vector<int> &B) {
	int b = int(Y % X);
	while (b > 10000) b -= X;
	while (b < -10000) b += X;
	A.push_back((Y - b) / X), B.push_back(b);
}

int64_t roundDouble(long double x) {
	if (x < 0) return -int64_t(0.5 - x);
	else return int64_t(x + 0.5);
}

void solve_range(int64_t lo, long double dist_lo_0, long double dist_lo_1, int64_t hi, long double dist_hi_0, long double dist_hi_1, std::vector<int> &a, std::vector<int> &b) {
	long double diff_lo = (dist_lo_1 - dist_lo_0), diff_hi = (dist_hi_1 - dist_hi_0);
	if (std::abs(diff_lo - diff_hi) < 0.01) return;
	// fprintf(stderr, "%lf %lf\n", (double) diff_lo, (double) diff_hi);

	long double dy = ((dist_lo_0 * 40000 - diff_lo * lo) - (dist_hi_0 * 40000 - diff_hi * hi)) / (diff_hi - diff_lo);
	fprintf(stderr, "%lf\n", (double) dy);
	int64_t y = roundDouble(dy);
	if (std::abs(y - dy) < 0.1) {
		fprintf(stderr, "%lf\n", double(((dist_lo_0 * 40000 - diff_lo * lo) - (dist_hi_0 * 40000 - diff_hi * hi)) / (diff_hi - diff_lo)));
		long double dist_y = query(X, y - 20000);
		fprintf(stderr, "%lf == %lf\n", double(dist_y * 40000), double(dist_lo_0 * 40000 + (y - lo) * diff_lo));
		fprintf(stderr, "%lf == %lf\n", double(dist_y * 40000), double(dist_hi_0 * 40000 + (y - hi) * diff_hi));
		if (equals(dist_y * 40000, dist_lo_0 * 40000 + (y - lo) * diff_lo) && equals(dist_y * 40000, dist_hi_0 * 40000 + (y - hi) * diff_hi)) {
			add(y - 20000, a, b);
			return;
		}
	}

	int64_t md = y - (y % 100000) + 50000 + (y % 100000 > 80000) * 100000;
	// if (md == lo) ++md;
	// if (md == hi) --md;
	long double dist_md_0 = query(X, md - 20000);
	long double dist_md_1 = query(X, md + 20000);

	solve_range(lo, dist_lo_0, dist_lo_1, md, dist_md_0, dist_md_1, a, b);
	solve_range(md, dist_md_0, dist_md_1, hi, dist_hi_0, dist_hi_1, a, b);
}

void solve(int subtask_id, int N) {
	int64_t lo = -3000000000ll + 50000, hi = 3000000000ll + 50000;
	std::vector<int> a, b;
	solve_range(lo, query(X, lo - 20000), query(X, lo + 20000), hi, query(X, hi - 20000), query(X, hi + 20000), a, b);
    the_lines_are(a, b);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 155 ms 1500 KB Incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 232 ms 1544 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 164 ms 1784 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 300 KB Output is correct
2 Correct 3 ms 296 KB Output is correct
3 Correct 3 ms 200 KB Output is correct
4 Correct 2 ms 280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 164 ms 1784 KB Incorrect
2 Halted 0 ms 0 KB -