QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#66836 | #5169. 夹娃娃 | Minion | 0 | 2821ms | 5376kb | C++23 | 3.9kb | 2022-12-09 12:10:49 | 2022-12-09 12:10:50 |
Judging History
answer
#include<cstdio>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
#define _is 1048576 * 3
#define _os 1048576
#define gc() ib[++bi]
#define pc(ch) ob[++bo] = ch
#define p 998244353
#define N 1024
#define add(x,y) (x >= p - y ? x + y - p : x + y)
#define sub(x,y) (x < y ? x - y + p : x - y)
using namespace std;
char ib[_is],ob[_os];int bi = -1,bo = -1;
int rd()
{
int x = 0;char ch = gc();
while(ch < 48 || ch > 57) ch = gc();
while(ch >= 48 && ch <= 57) x = x * 10 + ch - 48,ch = gc();return x;
}
void gs(char *s)
{
int l = -1;char ch = gc();
while(ch != 48 && ch != 49) ch = gc();
while(ch == 48 || ch == 49) s[++l] = ch,ch = gc();
s[++l] = 0;
}
void pr(int x)
{
char ch[20];int w = -1;
if(x == 0) ch[++w] = 48;
while(x) ch[++w] = x % 10 + 48,x /= 10;
fd(i,w,0) pc(ch[i]);pc('\n');
}
int n,q,P,a[20][N],m = 520,k;
char s[20];
int f[N],g[N],w[N + 1],iN;
void inc(int &x,int y) {x = x + y >= p ? x + y - p : x + y;}
int min(int x,int y) {return x < y ? x : y;}
int ksm(int x,int y)
{
int res = 1;
for(;y;y >>= 1,x = 1ll * x * x % p) if(y & 1) res = 1ll * res * x % p;
return res;
}
void pre()
{
int lg = 10;
w[0] = 1,w[1ll << lg] = ksm(3,p - 1 >> lg + 2);
fd(i,lg,1) w[1ll << i - 1] = 1ll * w[1ll << i] * w[1ll << i] % p;
fo(i,1,N - 1) w[i] = 1ll * w[i & i - 1] * w[i & -i] % p;
}
void DIF(int *a)
{
for(int l = N >> 1;l;l >>= 1) for(int i = 0,k = 0;i < N;i += l << 1,++k) fo(j,0,l - 1)
{
int x = a[i + j],y = 1ll * a[i + j + l] * w[k] % p;
a[i + j] = add(x,y),a[i + j + l] = sub(x,y);
}
}
void DIT(int *a)
{
for(int l = 1;l < N;l <<= 1) for(int i = 0,k = 0;i < N;i += (l << 1),++k) fo(j,0,l - 1)
{
int x = a[i + j],y = a[i + j + l];
a[i + j] = add(x,y),a[i + j + l] = 1ll * sub(x,y) * w[k] % p;
}
fo(i,1,N - 1 >> 1) a[i] ^= a[N - i] ^= a[i] ^= a[N - i];
fo(i,0,N - 1) a[i] = 1ll * a[i] * iN % p;
}
int t[530];
void M(int *f)
{
fo(i,512,520) t[i] = 0;
fo(i,0,8) fo(j,512,520) t[i + j] = (t[i + j] + 1ll * f[i] * g[j] + 1ll * g[i] * f[j]) % p;
fo(i,512,520) f[i] = g[i] = 0;
DIF(f),DIF(g);
fo(i,0,N - 1) f[i] = 1ll * f[i] * g[i] % p;
DIT(f);
fo(i,m + 1,N - 1) f[i] = 0;
fo(i,512,m) inc(f[i],t[i]);
}
int F[32768][N];
int main()
{
fread(ib,1,_is,stdin);
n = rd(),q = rd(),P = rd(),iN = ksm(N,p - 2);
pre();
int A = 0;
fo(i,1,n)
{
int m = rd();
if(m > A) A = m;
a[i][0] = 1;
while(m--)
{
int b = rd(),c = rd();
fo(j,0,N - 1) g[j] = 0;
fo(j,0,min(c,520 / b)) g[j * b] = 1;
M(a[i]);
}
}
if(A > 1)
{
fo(i,1,n) fo(j,0,m) F[1 << i - 1][j] = a[i][j];
fo(i,1,(1 << n) - 1)
{
int I = i & -i;
fo(j,0,N - 1) g[j] = 0;
fo(j,0,m) F[i][j] = F[I][j],g[j] = F[i ^ I][j];
M(F[i]);
}
}
int Q = q;
while(q--)
{
gs(s + 1),m = rd(),k = rd();
bool bz = 0;
fo(i,0,m) f[i] = 0;
if(A == 1)
{
f[0] = 1;
fo(i,1,n)
{
int l = 0;
if(s[i] == 49) l = k;
if(bz == 0)
{
fo(j,0,m) f[j] = a[i][j];
bz = 1;continue;
}
fo(j,l,m) g[j] = a[i][j];
fo(j,0,m) t[j] = f[j],f[j] = 0;
fo(j,0,m)
{
if(g[j] == 0) continue;
fo(j1,0,m - j) f[j + j1] = (f[j + j1] + 1ll * g[j] * t[j1]) % p;
}
}
}
else
{
int S = 0;
fd(i,n,1) S = S << 1 | (49 - s[i]);
fo(i,0,m) f[i] = F[S][i];
if(S) bz = 1;
fo(i,1,n)
{
if(s[i] == 48) continue;
if(bz == 0)
{
fo(j,k,m) f[j] = a[i][j];
bz = 1;continue;
}
fo(j,0,N - 1) g[j] = 0;
fo(j,k,m) g[j] = a[i][j];
if(m <= 200)
{
fo(j,0,m) t[j] = f[j],f[j] = 0;
fo(j,0,m)
{
if(g[j] == 0) continue;
fo(j1,0,m - j) f[j + j1] = (f[j + j1] + 1ll * g[j] * t[j1]) % p;
}
}
else M(f);
}
}
int ans = 0;
fo(i,0,m) inc(ans,f[i]);
pr(ans);
}
fwrite(ob,1,bo + 1,stdout);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3292kb
input:
1 521 998244353 39 520 520 11 22 414 8 95 18 229 356 26 407 316 10 24 26 19 61 11 130 482 476 420 15 192 193 208 24 19 233 494 217 275 294 26 28 439 20 272 277 28 198 5 335 22 8 28 17 154 78 6 13 175 17 2 5 477 256 200 4 1 36 427 371 439 23 10 65 426 25 24 27 121 29 28 13 12 453 0 520 1 1 519 1 1 51...
output:
0 922143638 98254957 38813343 922143633 38813338 98254946 922143620 98254933 922143604 38813302 38813288 922143562 38813247 38813220 38813188 38813150 98254715 38813047 922143273 98254516 38812814 922142999 98254191 922142723 38812257 38812058 98253436 922141847 38811240 922141173 38810463 38809988 ...
result:
wrong answer 1st lines differ - expected: '38813347', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 2821ms
memory: 5376kb
input:
15 52099 998244353 1 9 3 1 9 4 1 9 2 1 8 10 1 4 4 1 3 1 1 2 5 1 4 9 1 1 4 1 9 4 1 7 6 1 1 6 1 2 5 1 5 2 1 3 5 101000000001010 516 1 010001001010101 520 2 000000101000001 519 2 101011111100011 518 1 010110001000111 520 2 000110111100111 516 1 000100101001011 519 3 000111001010011 518 1 00001110010111...
output:
482093644 982351056 984621527 482093644 197109172 482093644 156913763 482093644 482093644 313827526 388388111 185636821 488905057 482093644 613969410 482093644 500957151 736763292 742601646 491824234 482093644 482093644 792173293 313827526 482093644 943753049 986567645 984621527 482093644 970998701 ...
result:
wrong answer 1st lines differ - expected: '993379058', found: '482093644'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%