結果

問題 No.2164 Equal Balls
ユーザー lddlinanlddlinan
提出日時 2023-03-26 22:16:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,962 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 89,176 KB
実行使用メモリ 159,016 KB
最終ジャッジ日時 2023-10-19 13:54:30
合計ジャッジ時間 11,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,380 KB
testcase_01 AC 3 ms
9,380 KB
testcase_02 AC 5 ms
11,428 KB
testcase_03 AC 4 ms
9,380 KB
testcase_04 AC 4 ms
11,428 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 5 ms
11,428 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};

#define MOD 998244353
#define GGG 3
void assert(int *p) { *p=0; }

int expit(LL b, LL m) {
  LL r=1;
  while(m) {
    if (m&1) { r=r*b; r%=MOD; }
    b=b*b; b%=MOD;
    m>>=1;
  }
  return r;
}

void fft(int *p, int n, char revert) {
  if ((MOD-1)%n) assert(0);
  int rt = expit(GGG, (MOD-1)/n);
  LL x, y;
  if (revert) {
    rt = expit(rt, MOD-2);
  }
  int b, i, j, l, t;
  LL w, ww, v, u, vv;
  for (i=1, j=0; i<n; i++) {
    b=n>>1;
    for (; j&b; b>>=1) j^=b; j^=b;
    if (i<j) { t=p[i]; p[i]=p[j]; p[j]=t; }
  }
  for (l=2; l<=n; l<<=1) {
    w=rt;
    for (i=l; i<n; i<<=1) w=(w*w)%MOD;
    for (i=0; i<n; i+=l) {
      ww=1;
      for (j=0; j<l/2; j++) {
        u=p[i+j]; v=p[i+j+l/2]; v*=ww; v%=MOD;
        vv=u+v; if (vv>=MOD) vv-=MOD;
        p[i+j]=vv;
        vv=u-v; if (vv<0) vv+=MOD;
        p[i+j+l/2]=vv;
        ww*=w; ww%=MOD;
      }
    }
  }
  if (revert) {
    x = expit(n, MOD-2);
    for (i=0; i<n; i++) {
      vv=p[i]; vv*=x; vv%=MOD; p[i]=vv;
    }
  }
}

#define MAXN 1<<20
int pbuf1[MAXN];
int pbuf2[MAXN];
int mpoly(int *p1, int c1, int *p2, int c2) {
  int m=c1+c2+1;
  int n=1; while(n<m) n<<=1;
  int i;
  LL v;
  for (i=0; i<=c1; i++) pbuf1[i]=p1[i];
  for (; i<n; i++) pbuf1[i]=0;
  for (i=0; i<=c2; i++) pbuf2[i]=p2[i];
  for (; i<n; i++) pbuf2[i]=0;
  fft(pbuf1, n, 0);
  fft(pbuf2, n, 0);
  for (i=0; i<n; i++) { v=pbuf1[i]; v*=pbuf2[i]; v%=MOD; pbuf1[i]=v; }
  fft(pbuf1, n, 1);
  i=n-1; while(i>0&&pbuf1[i]==0) i--;
  return i;
}

int ff[300][601*300];
int fc[300];
int as[200004], bs[200004];
int p1[800], p2[800];
int ft[400], ift[400];
int main() {
    int n, i, m, s, e, k, c, d, j, a, b, mc;
    LL v;
    ft[0]=ift[0]=1;
    for (i=1; i<=300; i++) {
        v=ft[i-1]; v*=i; v%=MOD;
        ft[i]=v; ift[i]=expit(v, MOD-2);
    }
    scanf("%d %d", &n, &m);
    for (i=0; i<n; i++) scanf("%d" ,&as[i]);
    for (i=0; i<n; i++) scanf("%d" ,&bs[i]);
    for (i=0; i<m; i++) {
        for (d=-300; d<=300; d++) ff[i][d+300]=1;
        mc=600;
        for (j=i; j<n; j+=m) {
            a=as[j]; b=bs[j];
            for (d=0; d<=300; d++) p1[d]=0;
            for (d=0; d<=a; d++) {
                v=ft[a]; v*=ift[d]; v%=MOD; v*=ift[a-d]; v%=MOD;
                p1[d]=v;
            }
            for (d=0; d<=300; d++) p2[d]=0;
            for (d=0; d<=b; d++) {
                v=ft[b]; v*=ift[d]; v%=MOD; v*=ift[b-d]; v%=MOD;
                p2[-d+300]=v;
            }
            c = mpoly(p1, 300, p2, 300);
            mc=min(mc, c);
            for (k=0; k<=mc; k++) {
                v=ff[i][k];  v*=pbuf1[k]; v%=MOD;
                ff[i][k]=v;
            }
        }
        for (k=mc+1; k<=600; k++) ff[i][k]=0;
        /*
        for (d=-300; d<=300; d++) {
            v=1;
            for (j=i; j<n; j+=m) {
                a=as[j]; b=bs[j];
                // [0, a] --> [-d, a-d];
                s=-d; e=a-d; if (s<0) s=0; if (e>b) e=b;
                if (s>e) { v=0; break; }
                os=s+d; oe=e+d;
                // sum(c(a, c1)*c(b, c1-d))
                v*=(e-s+1); v%=MOD;
            }
            ff[i][d+300]=v;
            if (v!=0) printf("%d %d: %d\n", i, d, v);
        }
        */
        fc[i]=600;
    }
    k=m; while(k>1) {
        s=0; e=k-1;
        while(s<e) {
            c = mpoly(ff[s], fc[s], ff[e], fc[s]);
            for (i=0; i<=c; i++) ff[s][i]=pbuf1[i];
            fc[s]=c;
            s++; e--;
                
        }
        k=(k+1)/2;
    }
    printf("%d\n", ff[0][300*m]);
    return 0;
}
0