結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-06-24 17:17:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,203 bytes
コンパイル時間 6,277 ms
コンパイル使用メモリ 338,016 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 23:02:18
合計ジャッジ時間 14,371 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 422 ms
6,944 KB
testcase_13 AC 533 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 542 ms
6,940 KB
testcase_16 AC 263 ms
6,940 KB
testcase_17 AC 455 ms
6,944 KB
testcase_18 AC 392 ms
6,944 KB
testcase_19 AC 435 ms
6,948 KB
testcase_20 AC 537 ms
6,940 KB
testcase_21 AC 530 ms
6,944 KB
testcase_22 AC 542 ms
6,944 KB
testcase_23 AC 29 ms
6,940 KB
testcase_24 AC 149 ms
6,940 KB
testcase_25 AC 394 ms
6,940 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define print(n) cout << (n) << endl
#define fprint(n) cout << setprecision(16) << (n) << endl
#define ceil_div(a, b) (((a) - 1) / (b) + 1)
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++)
#define ite(i, a) for (auto& i : a)
#define all(x) x.begin(), x.end()
#define lb(A, x) (lower_bound(all(A), x) - A.begin())
#define ub(A, x) (upper_bound(all(A), x) - A.begin())
using str = string;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using Pair = pair<int, int>;
using mint = modint1000000007;
using Mint = modint998244353;
template <class T>	using V = vector<T>;
template <class T>	using VV = V<V<T> >;
template <class T>	using PQ = priority_queue<T, V<T>, greater<T> >;
template <class T>	using PQR = priority_queue<T>;
template <class T>	using BIT = fenwick_tree<T>;
const ll INF = 4611686018427387903;
const int inf = 2147483647;
const ll mod = 1000000007;
const ll MOD = 998244353;
template <class T>  inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; }
template <class T>  inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; }
template <class T> inline void prints(V<T>& vec) { if (vec.size() == 0)return; cout << vec[0];	rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; }
inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; }
inline V<int> atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; }
inline V<int> Atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; }

struct Vector2 {
	ll x;
	ll y;

	Vector2() {
		this->x = 0;
		this->y = 0;
	}

	Vector2(ll x, ll y) {
		this->x = x;
		this->y = y;
	}
};

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(Vector2& v1, Vector2& v2) {
	ll x1 = get_mod(v1.x), y1 = get_mod(v1.y);
	ll x2 = get_mod(v2.x), y2 = get_mod(v2.y);
	return get_mod(x1 * y2 % mod - x2 * y1 % mod);
}

bool arg_sort(const Vector2& v1, const Vector2& v2) {
	_Float128 a, b;
	if (v1.x == 0) {
		a = (_Float128)INF;
	}
	else {
		a = (_Float128)v1.y / (_Float128)v1.x;
	}
	if (v2.x == 0) {
		b = (_Float128)INF;
	}
	else {
		b = (_Float128)v2.y / (_Float128)v2.x;
	}

	return (a < b);
}


int main(void) {
	int tmp, n = 0;	cin >> tmp;
	V<Vector2> vector(tmp);
	rep(i, 0, tmp) {
		ll x, y;	cin >> x >> y;
		if (x == 0 and y == 0) {
			continue;
		}
		if (x < 0) {
			x = -x;	y = -y;
		}
		vector[n] = Vector2(x, y);
		n++;
	}
	vector.resize(n);
	sort(all(vector), arg_sort);

	ll	S = 0, bh = 0;
	ll lx = 0, ly = 0;
	ite(v, vector) {
		ll x = v.x, y = v.y;
		Vector2 v1 = Vector2(lx, ly);
		Vector2 v2 = Vector2(lx + x, ly + y);
		S += area(v1, v2);
		S %= mod;
		bh += gcd(x, y);
		bh %= mod;
		lx = v2.x; ly = v2.y;
	}

	ll ans = (S + bh + 1) % mod;
	print(ans);

	return 0;
}

0