結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTS
提出日時 2024-12-02 15:31:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 202,108 KB
最終ジャッジ日時 2025-02-26 10:36:07
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
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);
}


mint area(pair<ll, ll>& v1, pair<ll, ll>& v2){
    mint x1 = v1.first, y1 = v1.second;
    mint x2 = v2.first, y2 = v2.second;
    return x1 * y2 - x2 * y1;
}


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 s = 0, bh = 0;
    ll lx = 0, ly = 0;
    for(auto&[x, y] : vectors) {
        pair<ll, ll> v1 = { lx, ly };
        pair<ll, ll> v2 = { lx + x, ly + y };
        s += area(v1, v2);
        bh += gcd(x, y);
        lx = v2.first, ly = v2.second;
    }
    mint ans = s + bh + 1;
    cout << ans.val() << endl;

    return 0;
}
0