結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tottoripapertottoripaper
提出日時 2019-03-08 21:45:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,252 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 174,740 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-05 19:44:24
合計ジャッジ時間 5,128 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 15 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 27 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 25 ms
4,380 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 36 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 26 ms
4,376 KB
testcase_29 AC 40 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 20 ms
4,380 KB
testcase_33 WA -
testcase_34 AC 20 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 32 ms
4,376 KB
testcase_38 AC 30 ms
4,376 KB
testcase_39 WA -
testcase_40 AC 45 ms
4,376 KB
testcase_41 WA -
testcase_42 AC 48 ms
4,380 KB
testcase_43 AC 24 ms
4,376 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