結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー snteasntea
提出日時 2015-12-18 14:18:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,907 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 148,496 KB
実行使用メモリ 4,620 KB
最終ジャッジ日時 2023-10-14 13:57:31
合計ジャッジ時間 4,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 WA -
testcase_15 AC 29 ms
4,556 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 16 ms
4,352 KB
testcase_19 WA -
testcase_20 AC 30 ms
4,620 KB
testcase_21 WA -
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 32 ms
4,352 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 38 ms
4,576 KB
testcase_30 AC 3 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 20 ms
4,352 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 25 ms
4,364 KB
testcase_43 WA -
testcase_44 AC 22 ms
4,352 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);
		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){
							//DEBUG(i);
							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&&f2){
					//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