結果

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

ソースコード

diff #

#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 += floor_sum(x, x, y, 0) + x * last;
		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;
}
0