結果

問題 No.523 LED
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-06-18 14:27:49
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,052 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 60,280 KB
最終ジャッジ日時 2024-04-27 02:26:42
合計ジャッジ時間 724 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:35:27: error: ‘powl’ was not declared in this scope
   35 |   constexpr i64 mod = i64(powl(10, 9)) + 7;
      |                           ^~~~
main.cpp:36:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   i64 n; scanf("%lld", &n);
      |          ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <tuple>
using namespace std;
using i64 = long long;

// 同じものを含む順列。
// n 種類のものがそれぞれ 2個、全部で 2n 個あるときの順列のパターン数。
// 答えは
//   (2*n)!
// ----------
//  (2!)^{n}

i64 mod_pow(i64 a, i64 n, i64 mod) {
  i64 res = 1LL;
  for(i64 p=a, x=n; x>0; x>>=1) {
    if(x & 1) { (res *= p) %= mod; }
    (p *= p) %= mod;
  }
  return res;
}

tuple<i64, i64, i64> extgcd(i64 x, i64 y) {
  if(y == 0) { return make_tuple(1, 0, x); }
  i64 a, b, d; tie(a, b, d) = extgcd(y, x%y);
  return make_tuple(b, a-x/y*b, d);
}

i64 mod_inv(i64 a, i64 m) {
  i64 x, y, d; tie(x, y, d) = extgcd(a, m);
  return d==1 ? (x % m + m) % m : -1;
}

int main(void) {
  constexpr i64 mod = i64(powl(10, 9)) + 7;
  i64 n; scanf("%lld", &n);
  i64 nume = 1;
  for(i64 i=1; i<=2*n; ++i) {
    nume *= i;
    nume %= mod;
  }
  i64 deno = mod_pow(2, n, mod); // 2! = 2
  i64 res = nume * mod_inv(deno, mod);
  res %= mod;
  printf("%lld\n", res);
  return 0;
}
0