結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー rogi52rogi52
提出日時 2023-10-17 14:21:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 2,123 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 204,828 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:22:06
合計ジャッジ時間 5,747 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 38 ms
4,348 KB
testcase_15 AC 83 ms
4,348 KB
testcase_16 AC 33 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 41 ms
4,348 KB
testcase_19 AC 53 ms
4,348 KB
testcase_20 AC 81 ms
4,348 KB
testcase_21 AC 48 ms
4,348 KB
testcase_22 AC 15 ms
4,348 KB
testcase_23 AC 68 ms
4,348 KB
testcase_24 AC 18 ms
4,348 KB
testcase_25 AC 47 ms
4,348 KB
testcase_26 AC 78 ms
4,348 KB
testcase_27 AC 59 ms
4,348 KB
testcase_28 AC 57 ms
4,348 KB
testcase_29 AC 83 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 42 ms
4,348 KB
testcase_33 AC 41 ms
4,348 KB
testcase_34 AC 31 ms
4,348 KB
testcase_35 AC 63 ms
4,348 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 50 ms
4,348 KB
testcase_38 AC 40 ms
4,348 KB
testcase_39 AC 13 ms
4,348 KB
testcase_40 AC 80 ms
4,348 KB
testcase_41 AC 21 ms
4,348 KB
testcase_42 AC 66 ms
4,348 KB
testcase_43 AC 33 ms
4,348 KB
testcase_44 AC 61 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct gaussian_integer {
    using gint = gaussian_integer;
    ll x, y;
    gaussian_integer() : x(0), y(0) {}
    gaussian_integer(ll x) : x(x), y(0) {}
    gaussian_integer(ll x, ll y) : x(x), y(y) {}

    friend ll abs(const gint& a) {
        return a.x * a.x + a.y * a.y;
    }
    friend gint conj(const gint& a) {
        return gint(a.x, -a.y);
    }
    gint operator-() { return gint(-x, -y); }
    gint operator+(const gint& r) { return gint(*this) += r; }
    gint operator-(const gint& r) { return gint(*this) -= r; }
    gint operator*(const gint& r) { return gint(*this) *= r; }
    gint operator/(const gint& r) { return gint(*this) /= r; }
    gint operator%(const gint& r) { return gint(*this) %= r; }
    gint& operator+=(const gint& r) { x += r.x, y += r.y; return *this; }
    gint& operator-=(const gint& r) { x -= r.x, y -= r.y; return *this; }
    gint& operator*=(const gint& r) { std::tie(x, y) = std::make_pair(x * r.x - y * r.y, x * r.y + y * r.x); return *this; }
    gint& operator/=(const gint& r) {
        assert(not(r.x == 0 and r.y == 0));

        auto near = [](ll a, ll b) {
            ll q = a / b, r = a - q * b;
            if(abs(r) > abs(r - b)) return q + 1;
            if(abs(r) > abs(r + b)) return q - 1;
            return q;
        };

        gint u = (*this) * conj(r);
        return *this = gint(near(u.x, abs(r)), near(u.y, abs(r)));
    }
    gint& operator%=(const gint& r) { return *this -= (*this) / r * r; }
    bool operator==(const gint& r) { return x == r.x and y == r.y; }
    bool operator!=(const gint& r) { return x != r.x or  y != r.y; }
    friend gint gcd(gint a, gint b) {
        if(b == gint(0, 0)) return a;
        return gcd(b, a % b);
    }
};

int main() {
	using gint = gaussian_integer;
	gint t; cin >> t.x >> t.y;
	gint g = gcd(t, conj(t));
	
	int N; cin >> N;
	int ans = 0;
	while(N--) {
		gint v; cin >> v.x >> v.y;
		if(g == gint(0, 0)) {
			if(v == gint(0, 0)) {
				ans++;
			}
		} else {
			if(v % g == gint(0, 0)) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}
0