QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#66600 | #5169. 夹娃娃 | Minion | 0 | 0ms | 0kb | C++23 | 2.6kb | 2022-12-09 09:31:51 | 2022-12-09 09:31:52 |
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 2048
#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][530],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 = 11;
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;
}
void M(int *f)
{
DIF(f),DIF(g);
fo(i,0,2047) f[i] = 1ll * f[i] * g[i] % p;
DIT(f);
fo(i,m + 1,2047) f[i] = 0;
}
int main()
{
fread(ib,1,_is,stdin);
n = rd(),q = rd(),P = rd(),iN = ksm(N,p - 2);
pre();
fo(i,1,n)
{
int m = rd();
a[i][0] = 1;
while(m--)
{
int b = rd(),c = rd();
fd(j,520,0) fo(d,1,min(c,b * d)) inc(a[i][j],a[i][j - b * d]);
}
}
while(q--)
{
gs(s + 1),m = rd(),k = rd();
fo(i,0,2047) f[i] = 0;
f[0] = 1;
fo(i,1,n)
{
int l = 0;
if(s[i] == 49) l = k;
fo(j,0,2047) g[j] = 0;
fo(j,l,m) g[j] = a[i][j];
M(f);
}
int ans = 0;
fo(i,0,m) inc(ans,f[i]);
pr(ans);
}
fwrite(ob,1,bo + 1,stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%