結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー yumakmc
提出日時 2016-02-26 21:33:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 159,392 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 14:02:42
合計ジャッジ時間 4,103 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 37 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}
int main() {
	long long int P, Q; cin >> P >> Q;
	int N; cin >> N;
	int ans = 0;
	if (!P&&!Q) {
		while (N--) {
			long long int X, Y; cin >> X >> Y;
			X = abs(X);
			Y = abs(Y);
			if (X || Y) {

			}
			else {
				ans++;
			}
		}
	}
	else if ((!P)||(!Q)) {
		bool s = false;
		if (P) {
			s = true;
			swap(P, Q);
		}
		assert(Q && (!P));

		while (N--) {
			long long int X, Y; cin >> X >> Y;
			X = abs(X);
			Y = abs(Y);
			if (s)swap(X, Y);
			if (X|| (Y%Q)) { continue;
			}else {
				ans++;
			}
		}
	}
	else {
		long long int agcd = gcd(P, Q);
		P /= agcd;
		Q /= agcd;
		while (N--) {
			long long int X, Y; cin >> X >> Y;
			X = abs(X);
			Y = abs(Y);
			if ((!(X%agcd) && (!(Y%agcd)))) {
				X /= agcd;
				Y /= agcd;
				if (P % 2 && Q % 2) {
					if ((X % 2) ^ (Y % 2)) {

					}
					else {
						ans++;
					}
				}
				else {
					ans++;
				}
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}
0