Submission #1781327


Source Code Expand

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

ostream &operator<<(ostream &os, __int128_t value) {
  if (ostream::sentry(os)) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[64];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    __int128_t len = end(buffer) - d;
    if (os.rdbuf()->sputn(d, len) != len) {
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is, __int128_t &value) {
  string in;
  is >> in;
  value = 0;
  for (const char &c : in) {
    if ('0' <= c && c <= '9') value = 10 * value + (c - '0');
  }
  if (in[0] == '-') value *= -1;
  return is;
}

const __int128_t mod = 1777777777;
struct ModCombination {
  ModCombination(__int128_t n) : n(n), F(n + 1, 1), I(n + 1, 1) {
    for (__int128_t i = 1; i <= n; ++i) F[i] = 1ll * i * F[i - 1] % mod;
    for (__int128_t i = mod - 2, j = F[n]; i; i >>= 1) {
      if (i & 1) I[n] = I[n] * j % mod;
      j = j * j % mod;
    }
    for (__int128_t i = n - 1; i; --i) I[i] = I[i + 1] * (i + 1ll) % mod;
  }

  __int128_t n;
  vector<int> F, I;

  __int128_t operator()(__int128_t p, __int128_t k) {
    if (p > n) exit(-1);
    if (k > p) return 0;
    return 1ll * F[p] * I[k] % mod * I[p - k] % mod;
  }
};

__int128_t mod_pow(__int128_t a, __int128_t x, __int128_t p = 1e9 + 7) {
  __int128_t ret = 1;
  for (__int128_t i = 1ll << 60; i; i >>= 1) {
    ret *= ret;
    ret %= p;
    if (x & i) {
      ret *= a;
      ret %= p;
    }
  }

  return ret;
}

__int128_t inv(__int128_t n, __int128_t p = 1e9 + 7) {
  return mod_pow(n, p - 2, p);
}

signed main() {
  __int128_t n, k;
  cin >> n >> k;

  vector<__int128_t> fact(k + 1, 1);
  for (__int128_t i = 1; i < fact.size(); ++i) {
    fact[i] *= i * fact[i - 1] % mod;
    fact[i] %= mod;
  }

  ModCombination mc(k);
  __int128_t t = 0;
  for (__int128_t i = 0; i <= k; ++i) {
    t += (mc(k, i) * fact[k - i] % mod) * (i & 1 ? -1 : 1);
    t %= mod;
  }

  __int128_t a = 1;
  for (__int128_t i = 0; i < k; ++i) {
    a *= n - i;
    a %= mod;
  }

  a *= inv(fact[k], mod);
  a %= mod;

  cout << a * t % mod << endl;
}

Submission Info

Submission Time
Task C - 高橋君、24歳
User Luzhiled
Language C++14 (GCC 5.4.1)
Score 40
Code Size 2335 Byte
Status WA
Exec Time 70 ms
Memory 11136 KB

Judge Result

Set Name small large
Score / Max Score 40 / 40 0 / 60
Status
AC × 15
AC × 23
WA × 4
Set Name Test Cases
small 00_small/small_00_sample1.txt, 00_small/small_00_sample2.txt, 00_small/small_00_sample3.txt, 00_small/small_00_sample4.txt, 00_small/small_01_rand_01.txt, 00_small/small_01_rand_02.txt, 00_small/small_01_rand_03.txt, 00_small/small_01_rand_05.txt, 00_small/small_01_rand_07.txt, 00_small/small_01_rand_08.txt, 00_small/small_01_rand_09.txt, 00_small/small_01_rand_10.txt, 00_small/small_01_rand_13.txt, 00_small/small_01_rand_14.txt, 00_small/small_01_rand_18.txt
large 00_small/small_00_sample1.txt, 00_small/small_00_sample2.txt, 00_small/small_00_sample3.txt, 00_small/small_00_sample4.txt, 00_small/small_01_rand_01.txt, 00_small/small_01_rand_02.txt, 00_small/small_01_rand_03.txt, 00_small/small_01_rand_05.txt, 00_small/small_01_rand_07.txt, 00_small/small_01_rand_08.txt, 00_small/small_01_rand_09.txt, 00_small/small_01_rand_10.txt, 00_small/small_01_rand_13.txt, 00_small/small_01_rand_14.txt, 00_small/small_01_rand_18.txt, 01_large/large_00_sample5.txt, 01_large/large_01_rand_01.txt, 01_large/large_01_rand_02.txt, 01_large/large_01_rand_03.txt, 01_large/large_01_rand_05.txt, 01_large/large_01_rand_07.txt, 01_large/large_01_rand_08.txt, 01_large/large_01_rand_09.txt, 01_large/large_01_rand_10.txt, 01_large/large_01_rand_13.txt, 01_large/large_01_rand_14.txt, 01_large/large_01_rand_18.txt
Case Name Status Exec Time Memory
00_small/small_00_sample1.txt AC 1 ms 256 KB
00_small/small_00_sample2.txt AC 1 ms 256 KB
00_small/small_00_sample3.txt AC 1 ms 256 KB
00_small/small_00_sample4.txt AC 1 ms 256 KB
00_small/small_01_rand_01.txt AC 1 ms 256 KB
00_small/small_01_rand_02.txt AC 1 ms 256 KB
00_small/small_01_rand_03.txt AC 1 ms 256 KB
00_small/small_01_rand_05.txt AC 1 ms 256 KB
00_small/small_01_rand_07.txt AC 1 ms 256 KB
00_small/small_01_rand_08.txt AC 1 ms 256 KB
00_small/small_01_rand_09.txt AC 1 ms 256 KB
00_small/small_01_rand_10.txt AC 1 ms 256 KB
00_small/small_01_rand_13.txt AC 1 ms 256 KB
00_small/small_01_rand_14.txt AC 1 ms 256 KB
00_small/small_01_rand_18.txt AC 1 ms 256 KB
01_large/large_00_sample5.txt AC 1 ms 256 KB
01_large/large_01_rand_01.txt AC 28 ms 4480 KB
01_large/large_01_rand_02.txt AC 54 ms 8576 KB
01_large/large_01_rand_03.txt AC 21 ms 3456 KB
01_large/large_01_rand_05.txt AC 69 ms 10880 KB
01_large/large_01_rand_07.txt AC 2 ms 384 KB
01_large/large_01_rand_08.txt WA 8 ms 1280 KB
01_large/large_01_rand_09.txt WA 41 ms 6528 KB
01_large/large_01_rand_10.txt AC 10 ms 1664 KB
01_large/large_01_rand_13.txt AC 70 ms 11136 KB
01_large/large_01_rand_14.txt WA 33 ms 5376 KB
01_large/large_01_rand_18.txt WA 61 ms 9856 KB