結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tottoripapertottoripaper
提出日時 2019-03-08 21:51:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 174,484 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 19:44:39
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 25 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 18 ms
4,376 KB
testcase_26 AC 37 ms
4,376 KB
testcase_27 AC 25 ms
4,376 KB
testcase_28 AC 27 ms
4,376 KB
testcase_29 AC 40 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 21 ms
4,380 KB
testcase_34 AC 20 ms
4,376 KB
testcase_35 AC 37 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 32 ms
4,380 KB
testcase_38 AC 29 ms
4,376 KB
testcase_39 AC 8 ms
4,376 KB
testcase_40 AC 46 ms
4,376 KB
testcase_41 AC 16 ms
4,376 KB
testcase_42 AC 48 ms
4,376 KB
testcase_43 AC 24 ms
4,380 KB
testcase_44 AC 39 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;

ll P, Q, N;

template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    T s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

bool f(ll p, ll q, ll x, ll y){
    if(p == 0 && q == 0){
        return x == 0 && y == 0;
    }

    ll s, t, g;
    std::tie(s, t, g) = extgcd(p, q);

    if(x % g != 0 || y % g != 0){
        return false;
    }

    ll s1 = (x / g) * s, t1 = (x / g) * t,
        s2 = (y / g) * t, t2 = (y / g) * s;

    if((p / g) % 2 != (q / g) % 2){
        return true;
    }

    return ((s1 + s2) & 1) == ((t1 + t2) & 1);
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> P >> Q >> N;

    int cnt = 0;
    
    for(int i=0;i<N;++i){
        ll X, Y;
        std::cin >> X >> Y;

        if(f(P, Q, X, Y)){
            cnt += 1;
        }
    }

    std::cout << cnt << std::endl;
}
0