結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー | drken1215 |
提出日時 | 2020-10-07 03:18:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,135 bytes |
コンパイル時間 | 2,157 ms |
コンパイル使用メモリ | 202,912 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-20 03:13:37 |
合計ジャッジ時間 | 4,795 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | RE | - |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
5,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 | - |
ソースコード
#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; }