Submission #21278321


Source Code Expand

Copy
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum P = 299993;
alias Mint = ModInt!P;
enum I = Mint(139302);

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Mint T = readInt();
      auto X = new Mint[N];
      auto Y = new Mint[N];
      foreach (j; 0 .. N) {
        X[j] = readInt();
        Y[j] = readInt();
      }
      
      auto zs = new Mint[N];
      auto ws = new Mint[N];
      foreach (j; 0 .. N) {
        zs[j] = X[j] + I * Y[j];
        ws[j] = X[j] - I * Y[j];
      }
      
      auto freqZ = new long[P];
      auto freqW = new long[P];
      foreach (z; 0 .. P) {
        Mint prod = 1;
        foreach (j; 0 .. N) {
          prod *= (z - zs[j]);
        }
        ++freqZ[prod.x];
      }
      foreach (w; 0 .. P) {
        Mint prod = 1;
        foreach (j; 0 .. N) {
          prod *= (w - ws[j]);
        }
        ++freqW[prod.x];
      }
      
      long ans;
      if (!T) {
        ans = 1L * P * P - 1L * (P - freqZ[0]) * (P - freqW[0]);
      } else {
        foreach (r; 1 .. P) {
          ans += freqZ[r] * freqW[(T / r).x];
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task L - Euclidean Distance Product
User hos_lyric
Language D (LDC 1.20.1)
Score 100
Code Size 4101 Byte
Status AC
Exec Time 290 ms
Memory 7700 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 33
Set Name Test Cases
Sample sample_00, sample_many_00
All deleted_sample_00, random_00, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, random_16, random_17, random_18, random_19, random_20, random_21, random_22, random_23, random_24, sample_00, sample_many_00, zero_random_00, zero_random_01, zero_random_02, zero_random_03, zero_random_04
Case Name Status Exec Time Memory
deleted_sample_00 AC 12 ms 7668 KB
random_00 AC 239 ms 7572 KB
random_01 AC 290 ms 7544 KB
random_02 AC 224 ms 7628 KB
random_03 AC 167 ms 7636 KB
random_04 AC 163 ms 7516 KB
random_05 AC 90 ms 7596 KB
random_06 AC 141 ms 7556 KB
random_07 AC 74 ms 7500 KB
random_08 AC 132 ms 7560 KB
random_09 AC 82 ms 7504 KB
random_10 AC 69 ms 7700 KB
random_11 AC 202 ms 7668 KB
random_12 AC 62 ms 7436 KB
random_13 AC 142 ms 7676 KB
random_14 AC 162 ms 7536 KB
random_15 AC 153 ms 7568 KB
random_16 AC 118 ms 7532 KB
random_17 AC 94 ms 7572 KB
random_18 AC 148 ms 7688 KB
random_19 AC 70 ms 7572 KB
random_20 AC 100 ms 7544 KB
random_21 AC 171 ms 7580 KB
random_22 AC 261 ms 7500 KB
random_23 AC 232 ms 7604 KB
random_24 AC 101 ms 7504 KB
sample_00 AC 51 ms 7572 KB
sample_many_00 AC 86 ms 7556 KB
zero_random_00 AC 73 ms 7464 KB
zero_random_01 AC 148 ms 7572 KB
zero_random_02 AC 240 ms 7476 KB
zero_random_03 AC 111 ms 7664 KB
zero_random_04 AC 185 ms 7620 KB