結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー Yang33Yang33
提出日時 2018-10-02 21:45:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,500 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 173,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 14:32:05
合計ジャッジ時間 3,565 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/10/02  Problem: yukicoder 321  / Link: http://yukicoder.me/problems/no/321  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

void solve() {
	int H, W; H = W = 100;
	cout << "what is vec(P,Q)?" << endl;
	int P, Q; cin >> P >> Q;
	VVI m(2*H, VI(2*W, 0));

	m[H][W] = 2;
	queue<PII>q;
	q.push(PII(H, W));
	while (!q.empty()) {
		PII a = q.front(); q.pop();
		for (int i = -1; i < 2; i += 2) {
			for (int j = -1; j < 2; j += 2) {
				int ny = a.first + P * i;
				int nx = a.second + Q * j;
#define IN(x,y,z) (x<=y&&y<z)
				if (IN(0, ny, 2 * H) && IN(0, nx, 2 * W) && !m[ny][nx]) {
					m[ny][nx] = 1;
					q.push(PII(ny, nx));
				}
			}
		}
		for (int i = -1; i < 2; i += 2) {
			for (int j = -1; j < 2; j += 2) {
				int ny = a.first + Q * i;
				int nx = a.second + P * j;
				if (IN(0, ny, 2 * H) && IN(0, nx, 2 * W) && !m[ny][nx]) {
					m[ny][nx] = 1;
					q.push(PII(ny, nx));
				}
			}
		}
	}
	FOR(i, -20, 21) {
		FOR(j, -20, 21) {
			cout << m[i+H][j+W] << " ";
		}cout << endl;
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	//solve(); return 0;
	LL P, Q; cin >> P >> Q;
	LL G = __gcd(P, Q);
	if (G) {
		P = P / G;
		Q = Q / G;
	}
	LL N; cin >> N;

	FOR(i, 0, N) {
		LL x, y; cin >> x >> y;
		if (P == 0 && P == Q) {
			if (x == 0 && x == y)ans++;
		}
		else {
			if (x%G == 0 && y%G == 0) {
				x /= G, y /= G;
				if (P & 1 && Q & 1) {
					if ((x + y) % 2 == 0) {
						ans++;
					}
				}
				else {
					ans++;
				}
			}
		}

	}
	
	
	cout << ans << "\n";

	return 0;
}
0