結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-21 21:40:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 89,736 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-25 22:59:13
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 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,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 111 ms
8,704 KB
testcase_13 AC 138 ms
8,832 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 137 ms
8,944 KB
testcase_16 AC 54 ms
6,944 KB
testcase_17 AC 90 ms
8,320 KB
testcase_18 AC 80 ms
7,680 KB
testcase_19 AC 87 ms
8,064 KB
testcase_20 AC 142 ms
8,960 KB
testcase_21 AC 142 ms
8,704 KB
testcase_22 AC 139 ms
8,832 KB
testcase_23 AC 8 ms
6,940 KB
testcase_24 AC 34 ms
6,940 KB
testcase_25 AC 80 ms
7,552 KB
testcase_26 AC 67 ms
6,940 KB
testcase_27 AC 59 ms
6,940 KB
testcase_28 AC 95 ms
8,320 KB
testcase_29 AC 45 ms
6,940 KB
testcase_30 AC 21 ms
6,944 KB
testcase_31 AC 16 ms
6,940 KB
testcase_32 AC 61 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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 get_mod(ll n) {
	if (n < 0) {
		return mod - (-n) % mod;
	}
	return n % mod;
}

ll area(V<ll>& v1, V<ll>& v2) {
	ll x1 = get_mod(v1[0]), y1 = get_mod(v1[1]);
	ll x2 = get_mod(v2[0]), y2 = get_mod(v2[1]);
	return get_mod(x1 * y2 % mod - x2 * y1 % 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 tmp, n = 0;	cin >> tmp;
	VV<ll> v(tmp, V<ll>(2));
	rep(i, 0, tmp) {
		ll x, y;	cin >> x >> y;
		if (x == 0 and y == 0) {
			continue;
		}
		if (y < 0) {
			x = -x;	y = -y;
		}
		v[n] = { x,y };
		n++;
	}
	v.resize(n);
	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