結果

問題 No.2164 Equal Balls
ユーザー lddlinanlddlinan
提出日時 2023-03-26 22:27:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,658 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 88,680 KB
実行使用メモリ 9,440 KB
最終ジャッジ日時 2023-10-19 13:55:10
合計ジャッジ時間 9,480 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,024 KB
testcase_01 AC 2 ms
5,028 KB
testcase_02 AC 3 ms
5,028 KB
testcase_03 AC 3 ms
5,156 KB
testcase_04 AC 3 ms
5,028 KB
testcase_05 AC 4 ms
4,972 KB
testcase_06 AC 4 ms
5,028 KB
testcase_07 AC 3 ms
5,028 KB
testcase_08 AC 86 ms
7,128 KB
testcase_09 AC 56 ms
5,800 KB
testcase_10 AC 44 ms
5,640 KB
testcase_11 AC 152 ms
9,080 KB
testcase_12 AC 82 ms
7,012 KB
testcase_13 AC 64 ms
6,276 KB
testcase_14 AC 80 ms
6,840 KB
testcase_15 AC 148 ms
8,824 KB
testcase_16 AC 75 ms
6,624 KB
testcase_17 AC 24 ms
4,972 KB
testcase_18 AC 105 ms
7,424 KB
testcase_19 AC 164 ms
9,440 KB
testcase_20 AC 91 ms
7,240 KB
testcase_21 AC 28 ms
5,000 KB
testcase_22 AC 38 ms
5,640 KB
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 dpc[301][301];
int dp[301][301][604];
void doit(int a, int b) {
    if (dpc[a][b]!=-1) return;
    int d;
    LL v;
    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;
    }
    int c = mpoly(p1, 300, p2, 300);
    dpc[a][b]=c;
    for (d=0; d<=c; d++) dp[a][b][d]=pbuf1[d];
}
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);
    }
    memset(dpc, 0xff, sizeof(dpc));
    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];
            doit(a, b);
            mc=min(mc, dpc[a][b]);
            for (k=0; k<=mc; k++) {
                v=ff[i][k];  v*=dp[a][b][k]; v%=MOD;
                ff[i][k]=v;
            }
        }
        fc[i]=mc;
        // for (k=mc+1; k<=600; k++) ff[i][k]=0;
        // 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[e]);
            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