結果

問題 No.321 (P,Q)-サンタと街の子供たち
コンテスト
ユーザー ゴリポン先生
提出日時 2026-10-22 14:19:47
言語 D
(dmd 2.113.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
WA  
実行時間 -
コード長 785 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,485 ms
コンパイル使用メモリ 193,660 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2026-10-22 14:19:56
合計ジャッジ時間 8,844 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(3011): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`
private typeof(T.init % T.init) gcdImpl(T)(T a, T b)
                                ^

ソースコード

diff #
raw source code

module main;
// http://rsujskf.s602.xrea.com/?yukicoder_321 より
// 2次元グリッド
import std;

void main()
{
	// 入力
	int P, Q;
	readln.chomp.formattedRead("%d %d", P, Q);
	int N = readln.chomp.to!int;
	alias T = Tuple!(int, "x", int, "y");
	auto pts = new T[](N);
	foreach (ref p; pts)
		readln.chomp.formattedRead("%d %d", p.x, p.y);
	// 答えの計算と出力
	if (P == 0) {
		if (Q == 0) {
			writeln(pts.count(T(0, 0)));
			return;
		}
		writeln(pts.count!(a => a.x % Q == 0 && a.y % Q == 0));
		return;
	}
	if (Q == 0) {
		writeln(pts.count!(a => a.x % P == 0 && a.y % P == 0));
		return;
	}
	int g = gcd(P, Q);
	P /= g, Q /= g;
	int ans = 0;
	foreach (p; pts) {
		if (p.x % g || p.y % g)
			continue;
		ans += (P + Q) % 2 || p.x + p.y % 2 == 0;
	}
	writeln(ans);
}
0