結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-04-19 18:51:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,933 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 159,672 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 03:45:48
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,948 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 75 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 132 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 65 ms
6,940 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 (Q == 0) swap(P, Q);
        if (P == 0 && Q == 0) {
            return x == 0 && y == 0;
        } else if (P == 0) {
            return abs(x) == abs(y) && abs(x) % Q == 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;
}
0