結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー te-shte-sh
提出日時 2017-06-22 15:07:21
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 96,196 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 14:43:28
合計ジャッジ時間 4,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 61 ms
4,376 KB
testcase_15 AC 97 ms
4,376 KB
testcase_16 AC 39 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 48 ms
4,376 KB
testcase_19 AC 63 ms
4,380 KB
testcase_20 AC 95 ms
4,380 KB
testcase_21 AC 57 ms
4,380 KB
testcase_22 AC 17 ms
4,380 KB
testcase_23 AC 81 ms
4,376 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 54 ms
4,380 KB
testcase_26 AC 92 ms
4,380 KB
testcase_27 AC 69 ms
4,380 KB
testcase_28 AC 68 ms
4,376 KB
testcase_29 AC 97 ms
4,380 KB
testcase_30 AC 3 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 50 ms
4,380 KB
testcase_33 AC 49 ms
4,380 KB
testcase_34 AC 36 ms
4,376 KB
testcase_35 AC 76 ms
4,376 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 59 ms
4,376 KB
testcase_38 AC 48 ms
4,376 KB
testcase_39 AC 16 ms
4,380 KB
testcase_40 AC 90 ms
4,376 KB
testcase_41 AC 26 ms
4,380 KB
testcase_42 AC 77 ms
4,376 KB
testcase_43 AC 39 ms
4,376 KB
testcase_44 AC 71 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions
import std.numeric;   // gcd, fft

void main()
{
  auto rd1 = readln.split.to!(long[]), p = rd1[0], q = rd1[1];
  auto n = readln.chomp.to!size_t;

  auto g1 = (p != 0 || q != 0) ? gcd(p, q) : 0;
  if (g1 != 0) { p /= g1; q /= g1; }

  auto g2 = (p != 0 || q != 0) ? gcd((p ^^ 2 - q ^^ 2).abs, 2 * q) : 0;

  auto r = 0;
  foreach (_; 0..n) {
    auto rd2 = readln.split.to!(long[]), x = rd2[0], y = rd2[1];

    if (g1 != 0) {
      if (x % g1 != 0 || y % g1 != 0) continue;
      x /= g1; y /= g1;
    }

    if (p == 0 && q == 0) {
      if (x == 0 && y == 0) ++r;
    } else if (p == 1 && q == 1) {
      if (x == y) ++r;
    } else if (p == 0 || q == 0 || g2 == 1) {
      ++r;
    } else {
      if ((q * y - p * x) % g2 == 0) ++r;
    }
  }

  writeln(r);
}
0