結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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