結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー snteasntea
提出日時 2015-12-19 01:09:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 2,087 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 148,680 KB
実行使用メモリ 4,664 KB
最終ジャッジ日時 2023-09-21 03:27:44
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <cmath>
#include <climits>
#include <cstdio>

using namespace std;

#define endl '\n'
#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define AALL(a,n) (a),(a)+(n)

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

#define int LL

pair<long long, long long> extgcd(long long a,long long b)
{
	if(b==1){
		return pair<long long, long long>(0,1);
	}
	pair<long long, long long> t=extgcd(b,a%b);
	return pair<long long, long long>(t.second,t.first-a/b*t.second);
}

long long gcd(long long x, long long y){
	return y==0 ? x : gcd(y, x%y);
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	LL p,q;
	int n;
	cin >> p >> q;
	cin >> n;
	vector<int> x(n),y(n);
	REP(i,n)	cin >> x[i] >> y[i];
	int ans = 0;
	if(p != 0 && q != 0){
		LL g = gcd(p,q);
		P tmp = extgcd(p/g,q/g);
		p /= g; q /= g;
		int k = tmp.first, l = tmp.second;
		REP(i,n){
			if(x[i]%g == 0 && y[i]%g == 0){
				x[i] /= g;
				y[i] /= g;
				//DEBUG(x[i]); DEBUG(y[i]); DEBUG(k); DEBUG(l);
				bool f1 = false, f2 = false;
				REP(a,2){
					REP(b,2){
						//DEBUG(k*p+l*q);
						/*if((((q*b+k*y[i])+(l*x[i]-p*a))%2+2)%2 == 0 && (((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){
							//DEBUG(i);
							f1 = true;
						}*/
						if(((k*x[i]-q*a+p*b+l*y[i])%2+2)%2 == 0 && ((p*a+l*x[i]+k*y[i]-q*b)%2+2)%2 == 0){
							f1 = true;
						}
					}
				}
				/*REP(a,2){
					REP(b,2){
						if((((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){
							//DEBUG(i);
							f2 = true;
						}
					}
				}*/
				if(f1){
					//DEBUG(i);
					ans++;
				}
			}
		}
	}else if(p == 0 && q == 0){
		REP(i,n){
			if(x[i] == 0 && y[i] == 0){
				ans++;
			}
		}
	}else{
		int num = p^q;
		REP(i,n){
			if(x[i]%num == 0 && y[i]%num == 0){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0