結果

問題 No.1999 Lattice Teleportation
ユーザー 沙耶花沙耶花
提出日時 2022-07-01 23:37:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,981 bytes
コンパイル時間 2,848 ms
コンパイル使用メモリ 210,284 KB
実行使用メモリ 11,744 KB
最終ジャッジ日時 2023-08-17 11:23:38
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 111 ms
11,720 KB
testcase_13 AC 167 ms
11,260 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 61 ms
8,008 KB
testcase_17 AC 99 ms
10,664 KB
testcase_18 AC 89 ms
10,204 KB
testcase_19 AC 94 ms
10,892 KB
testcase_20 AC 166 ms
11,744 KB
testcase_21 AC 165 ms
11,252 KB
testcase_22 AC 165 ms
11,464 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 36 ms
5,772 KB
testcase_25 AC 87 ms
10,336 KB
testcase_26 AC 73 ms
8,440 KB
testcase_27 AC 60 ms
7,708 KB
testcase_28 AC 103 ms
10,824 KB
testcase_29 AC 49 ms
6,856 KB
testcase_30 AC 22 ms
4,788 KB
testcase_31 AC 18 ms
4,384 KB
testcase_32 AC 66 ms
8,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint calc_area(vector<pll> vp) {
    int N = vp.size();
    mint res = 0;
    for (int i = 0; i < N; ++i) {
        mint px = vp[i].first, py = vp[(i+1)%N].first;
        mint qx = vp[i].second, qy = vp[(i+1)%N].second;
        res += px * qy - py * qx;
    }
    return res;
}

long long GCD(long long x, long long y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main() {
    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; ++i){
		cin >> X[i] >> Y[i];
		if(Y[i]<0){
			X[i]*=-1;
			Y[i]*=-1;
		}
	}
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return Y[i]*X[j] < Y[j]*X[i];
    });
    vector<pll> vp;
    vp.emplace_back(0, 0);
    for (auto i : ids) {
        auto p = vp.back();
        vp.emplace_back(p.first + X[i], p.second + Y[i]);
    }
    auto p = vp.back();
    int M = vp.size();
    for (int i = 1; i < M-1; ++i) {
        vp.emplace_back(p.first - vp[i].first, p.second - vp[i].second);
    }

    mint S = calc_area(vp);
    mint B = 0;
    for (int i = 0; i < vp.size(); ++i) {
        long long dx = vp[(i+1)%vp.size()].first - vp[i].first;
        long long dy = vp[(i+1)%vp.size()].second - vp[i].second;
        dx = abs(dx), dy = abs(dy);
        long long g = GCD(dx, dy);
        B += g;
    }
    mint res = (S + B) / 2;
	res = res+1;
    cout << res << endl;
}
0