結果
| 問題 | 
                            No.321 (P,Q)-サンタと街の子供たち
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-03-09 22:17:23 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 689 bytes | 
| コンパイル時間 | 1,490 ms | 
| コンパイル使用メモリ | 167,044 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-18 03:05:01 | 
| 合計ジャッジ時間 | 5,058 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 WA * 17 RE * 2 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int P, Q, N, g, ans = 0;
    cin >> P >> Q >> N;
    g = __gcd(P, Q);
    bool flag = false;
    if(g % 2 == 0){
        flag = (P % g % 2 == Q % g % 2);
    }
    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        if(g == 0){
            ans += (x == 0 && y == 0);
            continue;
        }
        if(x % g == 0 && y % g == 0){
            if(flag){
                x /= g, y /= g;
                ans += (x + y) % 2 == 0;
            }else{
                ans++;
            }
        }
    }
    cout << ans << '\n';
}