結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTS
提出日時 2022-02-22 18:19:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 84,740 KB
最終ジャッジ日時 2025-01-28 01:24:34
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll mod = 1000000007;


ll gcd(ll a, ll b) {
	a = abs(a);	b = abs(b);
	while (b != 0) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

ll area(V<ll>&v1, V<ll>&v2) {
	ll x1 = v1[0] % mod, y1 = v1[1] % mod;
	ll x2 = v2[0] % mod, y2 = v2[1] % mod;
	return (x1 * y2 % mod - x2 * y1 % mod) % mod;
}

bool arg_sort(const V<ll>&v1, const V<ll>&v2) {
	ll x1 = v1[0], y1 = v1[1];
	ll x2 = v2[0], y2 = v2[1];
	return (x1 * y2 > x2 * y1);
}


int main(void) {
	int n;	cin >> n;
	VV<ll> v(n, V<ll>(2));
	rep(i, 0, n) {
		ll x, y;	cin >> x >> y;
		if (y < 0) {
			x = -x;	y = -y;
		}
		v[i] = { x,y };
	}
	sort(all(v), arg_sort);

	ll	S = 0, bh = 0;
	ll lx = 0, ly = 0;
	for (auto& l : v) {
		ll x = l[0], y = l[1];
		V<ll> v1 = { lx,ly };
		V<ll> v2 = { lx + x,ly + y };
		S += area(v1, v2);
		S %= mod;
		bh += gcd(x, y);
		bh %= mod;
		lx = v2[0]; ly = v2[1];
	}

	ll ans = (S + bh + 1) % mod;
	cout << ans << endl;

	return 0;
}
0