結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー | drken1215 |
提出日時 | 2020-10-07 03:19:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 3,159 bytes |
コンパイル時間 | 2,818 ms |
コンパイル使用メモリ | 204,412 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 03:13:43 |
合計ジャッジ時間 | 5,187 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
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 | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 41 ms
6,940 KB |
testcase_15 | AC | 85 ms
6,944 KB |
testcase_16 | AC | 35 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 44 ms
6,940 KB |
testcase_19 | AC | 58 ms
6,944 KB |
testcase_20 | AC | 86 ms
6,940 KB |
testcase_21 | AC | 51 ms
6,944 KB |
testcase_22 | AC | 16 ms
6,940 KB |
testcase_23 | AC | 72 ms
6,940 KB |
testcase_24 | AC | 20 ms
6,940 KB |
testcase_25 | AC | 49 ms
6,940 KB |
testcase_26 | AC | 83 ms
6,940 KB |
testcase_27 | AC | 61 ms
6,940 KB |
testcase_28 | AC | 60 ms
6,940 KB |
testcase_29 | AC | 86 ms
6,944 KB |
testcase_30 | AC | 4 ms
6,940 KB |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 44 ms
6,944 KB |
testcase_33 | AC | 45 ms
6,940 KB |
testcase_34 | AC | 31 ms
6,944 KB |
testcase_35 | AC | 65 ms
6,940 KB |
testcase_36 | AC | 4 ms
6,940 KB |
testcase_37 | AC | 52 ms
6,940 KB |
testcase_38 | AC | 43 ms
6,940 KB |
testcase_39 | AC | 14 ms
6,940 KB |
testcase_40 | AC | 80 ms
6,944 KB |
testcase_41 | AC | 23 ms
6,940 KB |
testcase_42 | AC | 71 ms
6,944 KB |
testcase_43 | AC | 35 ms
6,940 KB |
testcase_44 | AC | 64 ms
6,940 KB |
ソースコード
#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; }