結果
問題 |
No.1999 Lattice Teleportation
|
ユーザー |
![]() |
提出日時 | 2024-12-02 18:01:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 1,225 bytes |
コンパイル時間 | 2,232 ms |
コンパイル使用メモリ | 205,692 KB |
最終ジャッジ日時 | 2025-02-26 10:38:11 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> #include <atcoder/math> using namespace std; using namespace atcoder; using mint = modint1000000007; using ll = long long; bool argsort(const pair<ll, ll>& v1, const pair<ll, ll>& v2) { auto&[x1, y1] = v1; auto&[x2, y2] = v2; return (x1 * y2 > x2 * y1); } void count(mint& ans, vector<pair<ll, ll> >& vectors, ll a_init){ mint last = 0; for(auto[x, y] : vectors){ ll a = a_init; mint s = 0; if(x < 0){ a = -a_init, x = -x; } s += x * last; if(x != 0){ s += floor_sum(x, x, y, 0); } ans += a * s; last += y; } } int main(){ int n; cin >> n; vector<pair<ll, ll> > vectors = {}; for(int i = 0; i < n; ++i){ ll x, y; cin >> x >> y; if(x == 0 && y == 0){ continue; } if(y < 0){ x = -x, y = -y; } vectors.push_back({x, y}); } sort(vectors.begin(), vectors.end(), argsort); mint ans = 1; for(auto&[x, y] : vectors){ ans += gcd(x, y); } count(ans, vectors, -1); reverse(vectors.begin(), vectors.end()); count(ans, vectors, 1); cout << ans.val() << endl; return 0; }