結果

問題 No.1999 Lattice Teleportation
ユーザー 👑 NachiaNachia
提出日時 2022-07-01 22:16:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,393 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 90,232 KB
実行使用メモリ 13,692 KB
最終ジャッジ日時 2024-05-04 16:38:06
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 53 ms
13,440 KB
testcase_13 AC 105 ms
13,436 KB
testcase_14 WA -
testcase_15 AC 109 ms
13,692 KB
testcase_16 AC 41 ms
8,508 KB
testcase_17 AC 69 ms
13,024 KB
testcase_18 AC 62 ms
12,624 KB
testcase_19 AC 65 ms
12,696 KB
testcase_20 AC 107 ms
13,560 KB
testcase_21 AC 105 ms
13,432 KB
testcase_22 AC 107 ms
13,308 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 26 ms
7,520 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<1000000007>;

struct Vec2 { long long x, y; };

std::vector<int> sort_points_by_argument(const std::vector<Vec2>& points) {
    std::vector<int> case_split[9];
    for (int i = 0; i < (int)points.size(); i++) {
        int case_id = 0;
        if (points[i].x == 0) case_id += 1;
        if (points[i].x > 0) case_id += 2;
        if (points[i].y == 0) case_id += 3;
        if (points[i].y > 0) case_id += 6;
        case_split[case_id].push_back(i);
    }
    auto sort_by_argument_small = [&points](int l, int r)->bool {
        return points[l].x * points[r].y - points[l].y * points[r].x > 0;
    };
    for (int t = 0; t < 9; t++) {
        std::sort(case_split[t].begin(), case_split[t].end(), sort_by_argument_small);
    }
    std::vector<int> res;
    res.reserve(points.size());
    for (int case_id : { 0, 1, 2, 4, 5, 8, 7, 6, 3 }) {
        std::copy(case_split[case_id].begin(), case_split[case_id].end(), std::back_inserter(res));
    }
    return res;
}

i64 GCD(i64 a, i64 b){
	return b ? GCD(b, a%b) : a;
}

i64 countLatticePointOnSegment(Vec2 p){
	return 1 + GCD(abs(p.x), abs(p.y));
}

int main(){
	int N; cin >> N;
	vector<Vec2> A(N);
	rep(i,N){
		cin >> A[i].x;
		cin >> A[i].y;
	}
	rep(i,A.size()){
		if(A[i].x == 0 && A[i].y == 0){
			swap(A[i], A.back());
			A.pop_back();
			i--;
		}
	}

	if(A.empty()){ cout << "0\n"; return 0; }
	if(A.size() == 1){ cout << countLatticePointOnSegment(A[0]) << '\n'; return 0; }

	for(int i=(int)A.size()-1; i>=0; i--) A.push_back({ -A[i].x, -A[i].y });
	vector<Vec2> B;
	for(auto i : sort_points_by_argument(A)) B.push_back(A[i]);

	modint ans = 0;
	for(auto p : B){
		if(p.x == 0 || p.y == 0) ans += p.x + p.y;
		else ans += GCD(abs(p.x), abs(p.y));
	}

	modint x = 0;
	modint y = 0;
	for(auto p : B){
		ans += x * (y + p.y) - y * (x + p.x);
		x += p.x;
		y += p.y;
	}

	ans += 2;
	ans /= 2;

	cout << ans.val() << '\n';
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0