結果

問題 No.1999 Lattice Teleportation
ユーザー 👑 colognecologne
提出日時 2022-03-21 17:13:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 121,352 KB
実行使用メモリ 17,692 KB
最終ジャッジ日時 2024-04-25 22:59:09
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 72 ms
17,620 KB
testcase_13 AC 98 ms
17,692 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 98 ms
17,208 KB
testcase_16 AC 44 ms
10,388 KB
testcase_17 AC 73 ms
16,404 KB
testcase_18 AC 67 ms
15,784 KB
testcase_19 AC 69 ms
15,900 KB
testcase_20 AC 96 ms
16,852 KB
testcase_21 AC 98 ms
17,244 KB
testcase_22 AC 98 ms
17,116 KB
testcase_23 AC 7 ms
6,944 KB
testcase_24 AC 29 ms
9,544 KB
testcase_25 AC 64 ms
15,856 KB
testcase_26 AC 53 ms
11,368 KB
testcase_27 AC 45 ms
10,836 KB
testcase_28 AC 75 ms
16,736 KB
testcase_29 AC 38 ms
9,592 KB
testcase_30 AC 18 ms
6,940 KB
testcase_31 AC 13 ms
6,944 KB
testcase_32 AC 49 ms
10,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <numeric>
#include <tuple>
#include <vector>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int N;
	cin >> N;

	vector<tuple<long long, long long, long long, long long>> ev;
	vector<pair<long long, long long>> pts;
	for (int i = 0; i < N; ++i)
	{
		long long a, b;
		cin >> a >> b;
		if (a == 0 && b == 0)
			continue;
		ev.emplace_back(-b, a, a, b);
		ev.emplace_back(b, -a, -a, -b);
	}
	sort(ev.begin(), ev.end(), [&](auto a, auto b)
		 {
		auto [ax, ay, a1, a2] = a;
		auto [bx, by, b1, b2] = b;
		bool ar = make_pair(ax, ay) > make_pair(0LL, 0LL);
		bool br = make_pair(bx, by) > make_pair(0LL, 0LL);
		if(ar!=br) return br;
		return ax*by > bx*ay; });
	long long x = 0, y = 0;
	for (auto [xe, ye, v1, v2] : ev)
	{
		x += v1;
		y += v2;
		pts.emplace_back(x, y);
	}

	const int MOD = 1e9 + 7;

	long long A = 0, B = 0;
	for (int i = 0; i < (int)pts.size(); ++i)
	{
		int j = (i + 1) % (int)pts.size();
		auto [ax, ay] = pts[i];
		auto [bx, by] = pts[j];

		A = (A + ((ax % MOD) * (by % MOD)) - ((bx % MOD) * (ay % MOD))) % MOD;
		B = (B + gcd(abs(ax - bx), abs(ay - by))) % MOD;
	}
	if (A < 0)
		A += MOD;
	if (A % 2 == 1)
		A += MOD;
	A /= 2;

	long long hB = B;
	if (hB < 0)
		hB += MOD;
	if (hB % 2 == 1)
		hB += MOD;
	hB /= 2;
	long long ans = (A + hB + 1) % MOD;

	cout << ans << endl;
}
0