結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-22 18:16:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,294 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 88,476 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-25 22:57:57
合計ジャッジ時間 4,023 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 121 ms
8,832 KB
testcase_13 AC 163 ms
8,704 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 61 ms
6,940 KB
testcase_17 AC 104 ms
8,192 KB
testcase_18 AC 93 ms
7,680 KB
testcase_19 AC 98 ms
7,936 KB
testcase_20 AC 161 ms
8,812 KB
testcase_21 AC 159 ms
8,832 KB
testcase_22 AC 159 ms
8,724 KB
testcase_23 AC 9 ms
6,944 KB
testcase_24 AC 37 ms
6,944 KB
testcase_25 AC 90 ms
7,552 KB
testcase_26 AC 73 ms
6,940 KB
testcase_27 AC 62 ms
6,940 KB
testcase_28 AC 105 ms
8,320 KB
testcase_29 AC 48 ms
6,940 KB
testcase_30 AC 22 ms
6,944 KB
testcase_31 AC 17 ms
6,944 KB
testcase_32 AC 67 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 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