結果
| 問題 | No.321 (P,Q)-サンタと街の子供たち |
| コンテスト | |
| ユーザー |
drken1215
|
| 提出日時 | 2020-10-07 03:18:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,135 bytes |
| コンパイル時間 | 1,876 ms |
| コンパイル使用メモリ | 194,236 KB |
| 最終ジャッジ日時 | 2025-01-15 03:11:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 4 WA * 36 RE * 1 |
ソースコード
#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;
}
drken1215