結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-05-26 01:46:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,958 bytes
コンパイル時間 3,258 ms
コンパイル使用メモリ 144,312 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 04:36:51
合計ジャッジ時間 9,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 35 ms
4,380 KB
testcase_15 AC 74 ms
4,380 KB
testcase_16 AC 30 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 38 ms
4,380 KB
testcase_19 AC 49 ms
4,384 KB
testcase_20 AC 74 ms
4,384 KB
testcase_21 AC 44 ms
4,380 KB
testcase_22 AC 14 ms
4,380 KB
testcase_23 AC 62 ms
4,384 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 42 ms
4,384 KB
testcase_26 AC 71 ms
4,380 KB
testcase_27 AC 54 ms
4,380 KB
testcase_28 AC 52 ms
4,384 KB
testcase_29 AC 74 ms
4,384 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 38 ms
4,384 KB
testcase_33 AC 38 ms
4,384 KB
testcase_34 AC 27 ms
4,384 KB
testcase_35 AC 58 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 46 ms
4,380 KB
testcase_38 AC 37 ms
4,380 KB
testcase_39 AC 12 ms
4,380 KB
testcase_40 AC 71 ms
4,380 KB
testcase_41 AC 19 ms
4,384 KB
testcase_42 AC 60 ms
4,380 KB
testcase_43 AC 30 ms
4,380 KB
testcase_44 AC 54 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.26 01:45:59
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

// gcd
template < typename T >
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
int main() {
    // int p, q;
    // cin >> p >> q;
    // const int MAX_X = 20;
    // const int MAX_Y = 20;
    // vector< vector< int > > g(MAX_X + 1, vector< int >(MAX_Y + 1,-1));
    // queue< pair< int, int > > que;
    // que.push({0, 0});
    // g[0][0] = 0;
    // int dx[] = {p, p, -p, -p, q, q, -q, -q}, dy[] = {q, -q, q, -q, p, -p, p, -p};
    // while (!que.empty()) {
    //     auto v = que.front();
    //     que.pop();
    //     int nx = v.first;
    //     int ny = v.second;
    //     for(int k = 0; k < 8; k++) {
    //         int x = nx + dx[k], y = ny + dy[k];
    //         if (x <= MAX_X && x >= 0 && y >= 0 && y <= MAX_Y && g[x][y] == -1) {
    //             que.push({x,y});
    //             g[x][y] = g[nx][ny] + 1;
    //         }
    //     }
    // }
    // for (int i = 0; i <= MAX_X; i++) {
    //     for (int j = 0; j <= MAX_Y; j++) {
    //         if (g[i][j] == -1) {
    //             cout << "x";
    //         }
    //         else {
    //             cout << g[i][j];
    //         }
    //     }
    //     cout << endl;
    // }
    int p, q;
    cin >> p >> q;
    int n;
    cin >> n;
    int g = gcd(p, q);
    if (g != 0) {
        p /= g;
        q /= g;
    }
    bool ok = false;
    if (p % 2 == 0 ^ q % 2 == 0) {
        ok = true;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (g == 0 && a == 0 && b == 0) {
            ans++;
        } else if (g != 0 && a % g == 0 && b % g == 0) {
            if (ok) {
                ans++;
            } else if (!((a / g) % 2 == 0 ^ (b / g) % 2 == 0)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0