結果

問題 No.695 square1001 and Permutation 4
ユーザー te-shte-sh
提出日時 2018-07-11 15:47:38
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,259 ms / 7,000 ms
コード長 1,178 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 99,260 KB
実行使用メモリ 42,944 KB
最終ジャッジ日時 2023-09-03 20:40:13
合計ジャッジ時間 8,830 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 47 ms
5,304 KB
testcase_02 AC 71 ms
12,520 KB
testcase_03 AC 43 ms
13,012 KB
testcase_04 AC 225 ms
13,248 KB
testcase_05 AC 299 ms
14,088 KB
testcase_06 AC 636 ms
23,000 KB
testcase_07 AC 449 ms
23,460 KB
testcase_08 AC 457 ms
23,720 KB
testcase_09 AC 653 ms
22,520 KB
testcase_10 AC 129 ms
6,624 KB
testcase_11 AC 1,259 ms
42,944 KB
testcase_12 AC 957 ms
42,156 KB
testcase_13 AC 922 ms
42,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.bigint;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

const mod1 = 168647939L, mod2 = 592951213L, mod = mod1*mod2;

void main()
{
  int n, m; readV(n, m);
  int[] x; readA(m, x);

  auto n2 = (n+1)/2, c = new uint[](n2);
  auto calc(int mod)
  {
    c[] = 0; c[0] = 1;
    foreach (i; 1..n2)
      foreach (j; 0..m)
        if (i >= x[j]) (c[i] += c[i-x[j]]) %= mod;

    auto r = 0uL;
    foreach (j; 0..m)
      foreach (i; max(0, n2-x[j])..min(n-x[j], n2))
        (r += c[i].to!ulong*c[n-1-(i+x[j])].to!ulong) %= mod;

    return r.to!long;
  }

  auto r1 = BigInt(calc(mod1)), r2 = BigInt(calc(mod2));
  long a, b; exEuclid(mod1, mod2, a, b);
  writeln(((r1*b*mod2+r2*a*mod1)%mod+mod)%mod);
}

pure T exEuclid(T)(T a, T b, ref T x, ref T y)
{
  auto g = a;
  x = 1;
  y = 0;
  if (b) {
    g = exEuclid(b, a%b, y, x);
    y -= a/b*x;
  }
  return g;
}
0