結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー hotpepsi
提出日時 2016-02-07 00:24:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 56,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 22:08:37
合計ジャッジ時間 3,312 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char *argv[])
{
	int P, Q, N;
	cin >> P >> Q >> N;
	int g;
	if (P == 0) {
		g = Q;
	} else if (Q == 0) {
		g = P;
	} else {
		g = gcd(P, Q);
	}
	int ans = 0;
	if (g == 0) {
		for (int i = 0; i < N; ++i) {
			int X, Y;
			cin >> X >> Y;
			ans += (X == 0 && Y == 0);
		}
	} else {
		int r = abs((P - Q) / g) % 2;
		for (int i = 0; i < N; ++i) {
			int X, Y;
			cin >> X >> Y;
			X = abs(X), Y = abs(Y);
			if ((X % g) == 0 && (Y % g) == 0) {
				if (r || (((X + Y) / g) % 2) == 0) {
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0