結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー drken1215drken1215
提出日時 2020-10-07 03:19:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 3,159 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 201,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 09:06:49
合計ジャッジ時間 5,159 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 40 ms
4,376 KB
testcase_15 AC 80 ms
4,380 KB
testcase_16 AC 33 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 40 ms
4,376 KB
testcase_19 AC 53 ms
4,376 KB
testcase_20 AC 81 ms
4,376 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 66 ms
4,380 KB
testcase_24 AC 19 ms
4,376 KB
testcase_25 AC 47 ms
4,380 KB
testcase_26 AC 77 ms
4,376 KB
testcase_27 AC 58 ms
4,380 KB
testcase_28 AC 60 ms
4,376 KB
testcase_29 AC 80 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 41 ms
4,376 KB
testcase_33 AC 40 ms
4,376 KB
testcase_34 AC 30 ms
4,380 KB
testcase_35 AC 61 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 49 ms
4,384 KB
testcase_38 AC 40 ms
4,376 KB
testcase_39 AC 12 ms
4,376 KB
testcase_40 AC 75 ms
4,380 KB
testcase_41 AC 21 ms
4,376 KB
testcase_42 AC 65 ms
4,376 KB
testcase_43 AC 32 ms
4,376 KB
testcase_44 AC 59 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// Gauss Integer
struct gint {
    long long x, y;
    constexpr gint() : x(0), y(0) { }
    constexpr gint(long long x) : x(x), y(0) { }
    constexpr gint(long long x, long long y) : x(x), y(y) { }
    friend constexpr long long abs(const gint& r) noexcept {
        return r.x * r.x + r.y * r.y;
    }
    constexpr gint operator - () const noexcept {
        return gint(-x, -y);
    }
    constexpr gint operator + (const gint& r) const noexcept { return gint(*this) += r; }
    constexpr gint operator - (const gint& r) const noexcept { return gint(*this) -= r; }
    constexpr gint operator * (const gint& r) const noexcept { return gint(*this) *= r; }
    constexpr gint operator / (const gint& r) const noexcept { return gint(*this) /= r; }
    constexpr gint operator % (const gint& r) const noexcept { return gint(*this) %= r; }
    constexpr gint& operator += (const gint& r) noexcept {
        x += r.x, y += r.y;
        return *this;
    }
    constexpr gint& operator -= (const gint& r) noexcept {
        x -= r.x, y -= r.y;
        return *this;
    }
    constexpr gint& operator *= (const gint& r) noexcept {
        auto tx = x * r.x - y * r.y;
        auto ty = x * r.y + y * r.x;
        x = tx, y = ty;
        return *this;
    }
    constexpr gint& operator /= (const gint& r) noexcept {
        long long a = x, b = y, c = r.x, d = r.y;        
    	assert(c != 0 || d != 0);
        long long tx = (a * c + b * d) / (c * c + d * d);
        long long ty = (b * c - a * d) / (c * c + d * d);
        gint res;
        long long dmin = -1;
        for (long long nx = tx - 1; nx <= tx + 1; ++nx) {
            for (long long ny = ty - 1; ny <= ty + 1; ++ny) {
                gint q(nx, ny);
                long long d = abs((*this) - q * r);
                if (dmin == -1 || dmin > d) {
                    dmin = d;
                    res = q;
                }
            }
        }
        return *this = res;
    }
    constexpr gint& operator %= (const gint& r) noexcept {
        gint q = (*this) / r;
        return (*this) -= q * r;
    }
    constexpr bool operator == (const gint& r) const noexcept {
        return x == r.x && y == r.y;
    }
    constexpr bool operator != (const gint& r) const noexcept {
        return x != r.x || y != r.y;
    }
    friend ostream& operator << (ostream& os, const gint& r) noexcept {
        if (r.x == 0 && r.y == 0) return os << "0";
        else if (r.x == 0) return os << r.y << "i";
        else os << r.x;
        if (r.y == 0) return os;
        else if (r.y > 0) return os << " + " << r.y << "i";
        else return os << " - " << (-r.y) << "i";
    }
    friend gint gcd(const gint& x, const gint& y) {
        if (y == 0) return x;
        else return gcd(y, x % y);
    }
};

int main() {
    long long N, P, Q;
    cin >> P >> Q;
    gint G = gcd(gint(P, Q), gint(P, -Q));
    cin >> N;
    int res = 0;
    while (N--) {
        long long X, Y;
        cin >> X >> Y;
        if (G == 0) {
            if (gint(X, Y) == 0) ++res;
        }
        else if (gint(X, Y) % G == 0) ++res;
    }
    cout << res << endl;
}
0