QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553357 | #7558. Abstract | ucup-team1231# | RE | 0ms | 0kb | C++14 | 4.9kb | 2024-09-08 12:12:58 | 2024-09-08 12:13:02 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const int MOD=998244353;
#define sz(t) int((t).size())
vi operator + (const vi&A,const vi&B) {
vi C(max(sz(A),sz(B)));
for(int i=0;i<sz(A);++i) C[i]=A[i];
for(int i=0;i<sz(B);++i) (C[i]+=B[i])%=MOD;
return C;
}
int K;
ll qp(ll a,ll b) {
ll x=1; a%=MOD;
while(b) {
if(b&1) x=x*a%MOD;
a=a*a%MOD; b>>=1;
}
return x;
}
const int SZ = 1000005;
ll w[2][SZ];
void fftinit(int n) {
for(K=1;K<n;K<<=1);
ll ww=qp(3,(MOD-1)/K);
w[0][0]=1;
for(int i=1;i<=K;++i)
w[0][i]=w[0][i-1]*ww%MOD;
for(int i=0;i<=K;++i) w[1][i]=w[0][K-i];
}
void fft(int*a,int o) {
for(int i=0;i<K;++i) {
int br=i,s=0;
for(int j=1;j<K;j<<=1)
s=s*2+br%2,br/=2;
if(i<s) swap(a[i],a[s]);
}
for(int i=2;i<=K;i<<=1)
for(int l=0;l<K;l+=i)
for(int j=0;j<(i/2);++j) {
int &p=a[j+l],&q=a[l+j+(i/2)];
ll t=q*(ll)w[o][K/i*j]%MOD;
q=(p-t+MOD)%MOD;
p=(p+t)%MOD;
}
if(!o) return;
ll rk=qp(K,MOD-2);
for(int i=0;i<K;++i) a[i]=a[i]*(ll)rk%MOD;
}
vi operator * (const vi&A,const vi&B) {
if(A.empty()) return A;
if(B.empty()) return B;
int u=sz(A)+sz(B)-1;
vi C(u);
static int ta[SZ],tb[SZ];
fftinit(u);
for(int i=0;i<K;++i) ta[i]=(i<sz(A))?A[i]:0;
for(int i=0;i<K;++i) tb[i]=(i<sz(B))?B[i]:0;
fft(ta,0);fft(tb,0);
for(int i=0;i<K;++i) ta[i]=ta[i]*(ll)tb[i]%MOD;
fft(ta,1);
for(int i=0;i<u;++i) C[i]=ta[i];
return C;
}
int fac[SZ], ifac[SZ];
void init(int n) {
fac[0] = 1;
for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
ifac[n] = qp(fac[n], MOD - 2);
for(int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % MOD;
}
vi comp(vi A) {
int n = A.size() - 1;
vi B(n + 1);
for(int i = 0; i <= n; i++) A[i] = 1LL * A[i] * fac[i] % MOD;
reverse(A.begin(), A.end());
for(int i = 0; i <= n; i++) B[i] = ifac[i];
vi C = A * B;
C.resize(n + 1);
reverse(C.begin(), C.end());
for(int i = 0; i <= n; i++) C[i] = 1LL * C[i] * ifac[i] % MOD;
return C;
}
int pw[10];
string s[100000];
string p[100000];
int l[100000][5],r[100000][5];
int diff[26][26][26][26][26];
int main() {
pw[0] = 1;
for(int i = 0; i < 5; i++) pw[i + 1] = pw[i] * 26;
int i,j;
int n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i] >> p[i];
for (j = 0; j < 5; j++) {
if (p[i][j] == '<') l[i][j] = 0,r[i][j] = s[i][j]-'A'-1;
else if (p[i][j] == '=') l[i][j] = r[i][j] = s[i][j]-'A';
else l[i][j] = s[i][j]-'A'+1,r[i][j] = 25;
}
}
int k,m;
vi poly(n+1);
for (i = 0; i < 32; i++) {
memset(diff,0,sizeof(diff));
int b = (__builtin_popcount(i) & 1) ? -1:1;
for (j = 0; j < n; j++) {
for (m = 0; m < 5; m++) {
if (l[j][k] >= r[j][k]-((i >> m) & 1)+1) break;
}
if (m < 5) continue;
for (k = 0; k < 32; k++) {
int I[5];
for (m = 0; m < 5; m++) {
if (k & (1 << m)) I[m] = l[j][k];
else I[m] = r[j][k]-((i >> m) & 1)+1;
}
diff[I[0]][I[1]][I[2]][I[3]][I[4]] += b;
}
}
int I[5];
for (j = 0; j < 5; j++) {
for (I[0] = 0; I[0] < 26; I[0]++) {
for (I[1] = 0; I[1] < 26; I[1]++) {
for (I[2] = 0; I[2] < 26; I[2]++) {
for (I[3] = 0; I[3] < 26; I[3]++) {
for (I[4] = 0; I[4] < 26; I[4]++) {
if (I[j] > 0) {
I[j]--;
int v = diff[I[0]][I[1]][I[2]][I[3]][I[4]];
I[j]++;
diff[I[0]][I[1]][I[2]][I[3]][I[4]] += v;
}
}
}
}
}
}
}
for (I[0] = 0; I[0] < 26-(i & 1); I[0]++) {
for (I[1] = 0; I[1] < 26-((i >> 1) & 1); I[1]++) {
for (I[2] = 0; I[2] < 26-((i >> 2) & 1); I[2]++) {
for (I[3] = 0; I[3] < 26-((i >> 3) & 1); I[3]++) {
for (I[4] = 0; I[4] < 26-((i >> 4) & 1); I[4]++) {
poly[diff[I[0]][I[1]][I[2]][I[3]][I[4]]]++;
}
}
}
}
}
}
vi poly2 = comp(poly);
for (i = 1; i <= n; i += 2) poly2[i] = (MOD-poly2[i]) % MOD;
for (i = 0; i <= n; i++) printf("%d ",poly2[i]);
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 1 1 1 1 2 2 3