結果
問題 |
No.321 (P,Q)-サンタと街の子供たち
|
ユーザー |
![]() |
提出日時 | 2016-04-19 18:47:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,843 bytes |
コンパイル時間 | 1,203 ms |
コンパイル使用メモリ | 161,088 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 14:08:51 |
合計ジャッジ時間 | 4,963 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 WA * 28 RE * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; namespace { typedef double real; typedef long long ll; template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template<class T> istream& operator>>(istream& is, vector<T>& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& x, ll& y) { ll g = a; x = 1LL; y = 0LL; if (b != 0LL) { g = extgcd(b, a % b, y, x); y -= (a / b) * x; } return g; } ll P, Q; int N; bool eql2(ll a, ll b) { a = abs(a); b = abs(b); return a % 2 == b % 2; } bool check(ll x, ll y) { if (P == 0 && Q == 0) return x == 0 && y == 0; if (P == Q) return x == y && (x % P == 0); ll n, m; ll g = extgcd(P, Q, n, m); ll a, b; extgcd(Q, P, a, b); ll dP = lcm(P, Q) / P; ll dQ = lcm(P, Q) / Q; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if ( eql2(n + i * dP, a + j * dQ) && eql2(m + (-i) * dQ, b + (-i) * dP) ) { return true; } } } return false; } void solve() { cin >> P >> Q >> N; int ans = 0; for (int i = 0; i < N; i++) { ll x, y; cin >> x >> y; //cout << x << " " << y << " -> " << check(x, y) << endl; ans += check(x, y); } cout << ans << endl; } } int main() { solve(); return 0; }