結果
| 問題 | No.321 (P,Q)-サンタと街の子供たち |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-17 14:34:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 6,931 bytes |
| コンパイル時間 | 2,013 ms |
| コンパイル使用メモリ | 197,168 KB |
| 最終ジャッジ日時 | 2025-02-17 08:11:20 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#line 1 "gaussian_integer.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/321"
#line 2 "/Users/korogi/Desktop/cp-library-2/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
#line 2 "/Users/korogi/Desktop/cp-library-2/src/utility/rep_itr.hpp"
template < class T > struct itr {
T i, d;
constexpr itr(const T i) noexcept : i(i), d(1) {}
constexpr itr(const T i, const T d) noexcept : i(i), d(d) {}
void operator++() noexcept { i += d; }
constexpr int operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept {
return d > 0 ? i < x.i : i > x.i;
}
};
template < class T > struct rep {
const itr< T > s, t;
constexpr rep(const T t) noexcept : s(0), t(t) {}
constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
constexpr auto begin() const noexcept { return s; }
constexpr auto end() const noexcept { return t; }
};
template < class T > struct revrep {
const itr < T > s, t;
constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
constexpr auto begin() const noexcept { return s; }
constexpr auto end() const noexcept { return t; }
};
#line 2 "/Users/korogi/Desktop/cp-library-2/src/utility/io.hpp"
namespace scanner {
struct sca {
template < class T > operator T() {
T s; cin >> s; return s;
}
};
struct vec {
int n;
vec(int n) : n(n) {}
template < class T > operator vector< T >() {
vector< T > v(n);
for(T& x : v) cin >> x;
return v;
}
};
struct mat {
int h,w;
mat(int h, int w) : h(h), w(w) {}
template < class T > operator vector< vector< T > >() {
vector m(h, vector< T >(w));
for(vector< T >& v : m) for(T& x : v) cin >> x;
return m;
}
};
struct speedup {
speedup() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} su;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }
namespace printer {
void precision(int d) {
cout << fixed << setprecision(d);
}
void flush() {
cout.flush();
}
}
int print() { cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
cout << h; if(sizeof...(tail)) cout << ' ';
return print(forward<tail>(t)...);
}
template < class T > int print(vector< T > a, char sep = ' ') {
int n = a.size();
for(int i : rep(n)) cout << a[i] << (i != n - 1 ? sep : '\n');
return 0;
}
template < class T > int print(vector< vector< T > > a) {
if(a.empty()) return 0;
int h = a.size(), w = a[0].size();
for(int i : rep(h)) for(int j : rep(w)) cout << a[i][j] << (j != w - 1 ? ' ' : '\n');
return 0;
}
#line 2 "/Users/korogi/Desktop/cp-library-2/src/utility/key_val.hpp"
template < class K, class V >
struct key_val {
K key; V val;
key_val() {}
key_val(K key, V val) : key(key), val(val) {}
};
#line 2 "/Users/korogi/Desktop/cp-library-2/src/utility/vec_op.hpp"
template < class T >
key_val< int, T > max_of(const vector< T >& a) {
int i = max_element(a.begin(), a.end()) - a.begin();
return {i, a[i]};
}
template < class T >
key_val< int, T > min_of(const vector< T >& a) {
int i = min_element(a.begin(), a.end()) - a.begin();
return {i, a[i]};
}
template < class T >
T sum_of(const vector< T >& a) {
T sum = 0;
for(const T x : a) sum += x;
return sum;
}
template < class T >
vector<int> freq_of(const vector< T >& a, T L, T R) {
vector<int> res(R - L);
for(const T x : a) res[x - L]++;
return res;
}
template < class T >
vector<int> freq_of(const vector< T >& a, T R) {
return freq_of(a, T(0), R);
}
template < class T >
struct prefix_sum {
vector< T > s;
prefix_sum(const vector< T >& a) : s(a) {
s.insert(s.begin(), T(0));
for(int i : rep(a.size())) s[i + 1] += s[i];
}
// [L, R)
T sum(int L, int R) {
return s[R] - s[L];
}
};
#line 2 "/Users/korogi/Desktop/cp-library-2/src/number/gaussian_integer.hpp"
struct gaussian_integer {
using gint = gaussian_integer;
ll x, y;
gaussian_integer() : x(0), y(0) {}
gaussian_integer(ll x) : x(x), y(0) {}
gaussian_integer(ll x, ll y) : x(x), y(y) {}
friend ll abs(const gint& a) {
return a.x * a.x + a.y * a.y;
}
friend gint conj(const gint& a) {
return gint(a.x, -a.y);
}
gint operator-() { return gint(-x, -y); }
gint operator+(const gint& r) { return gint(*this) += r; }
gint operator-(const gint& r) { return gint(*this) -= r; }
gint operator*(const gint& r) { return gint(*this) *= r; }
gint operator/(const gint& r) { return gint(*this) /= r; }
gint operator%(const gint& r) { return gint(*this) %= r; }
gint& operator+=(const gint& r) { x += r.x, y += r.y; return *this; }
gint& operator-=(const gint& r) { x -= r.x, y -= r.y; return *this; }
gint& operator*=(const gint& r) { std::tie(x, y) = std::make_pair(x * r.x - y * r.y, x * r.y + y * r.x); return *this; }
gint& operator/=(const gint& r) {
assert(not(r.x == 0 and r.y == 0));
auto near = [](ll a, ll b) {
ll q = a / b, r = a - q * b;
if(abs(r) > abs(r - b)) return q + 1;
if(abs(r) > abs(r + b)) return q - 1;
return q;
};
gint u = (*this) * conj(r);
return *this = gint(near(u.x, abs(r)), near(u.y, abs(r)));
}
gint& operator%=(const gint& r) { return *this -= (*this) / r * r; }
bool operator==(const gint& r) { return x == r.x and y == r.y; }
bool operator!=(const gint& r) { return x != r.x or y != r.y; }
friend gint gcd(gint a, gint b) {
if(b == gint(0, 0)) return a;
return gcd(b, a % b);
}
};
#line 5 "gaussian_integer.test.cpp"
int main() {
using gint = gaussian_integer;
gint t; t.x = in(), t.y = in();
gint g = gcd(t, conj(t));
int N = in();
int ans = 0;
for(int _ : rep(N)) {
gint v; v.x = in(), v.y = in();
if(g == 0) {
if(v == 0) ans++;
} else {
if(v % g == 0) ans++;
}
}
print(ans);
}