QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72872 | #5414. Stop, Yesterday Please No More | chenshi# | AC ✓ | 542ms | 56056kb | C++ | 2.4kb | 2023-01-19 19:09:10 | 2023-01-19 19:09:21 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int o=2100,O=1e6+10,MOD=998244353;
inline int fix(int x){return x+(x>>31&MOD);}
inline int qp(int b,int f){int res=1;for(;f;f>>=1,b=b*1ll*b%MOD) if(f&1) res=res*1ll*b%MOD;return res;}
int T,n,m,K,f[o][o],g[o][o],w[o],bt1,bt2,rev[o],len,ans,s,lx,rx,ly,ry,tmp[o][o];char opt[O];
inline void init(){
int bt=11;
w[1<<(bt-1)]=1;
for(int i=(1<<(bt-1))+1,j=qp(3,(MOD-1)/(1<<bt));i<(1<<bt);++i) w[i]=w[i-1]*1ll*j%MOD;
for(int i=(1<<(bt-1));--i;) w[i]=w[i<<1];
}
inline void ntt(int*a,int n,bool inv){
for(int i=1;i<n;++i) if(rev[i]<i) swap(a[i],a[rev[i]]);
for(int md=1;md<n;md<<=1) for(int i=0;i<n;i+=md<<1) for(int j=0,x,y;j<md;++j)
x=a[i+j],y=a[i+j+md]*1ll*w[j+md]%MOD,a[i+j]=fix(x+y-MOD),a[i+j+md]=fix(x-y);
if(inv) for(int i=1,j=n-1;i<j;swap(a[i++],a[j--]));
}
inline void foo(bool inv){
for(int i=1;i<(1<<bt2);++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bt2-1));
for(int i=0,coef=qp(1<<bt2,MOD-2);i<(1<<bt1);++i){
ntt(f[i],1<<bt2,inv);
if(inv) for(int j=0;j<(1<<bt2);++j) f[i][j]=f[i][j]*1ll*coef%MOD;
else ntt(g[i],1<<bt2,inv);
}
}
inline void trans(int a[][o]){
for(int i=0;i<(1<<bt1);++i) for(int j=0;j<(1<<bt2);++j) tmp[i][j]=a[i][j];
for(int i=0;i<(1<<bt1);++i) for(int j=0;j<(1<<bt2);++j) a[j][i]=tmp[i][j];
}
inline void bar(bool inv){foo(inv);trans(f);trans(g);swap(bt1,bt2);foo(inv);}
inline void mult(){
if(n*m<=100){
for(int i=n*2;i>n;--i) for(int j=m*2;j>m;--j)
for(int k=1;k<=n;++k) for(int $=1;$<=m;++$) f[i][j]+=f[k][$]*g[i-k][j-$];
return;
}
bar(0);
for(int i=0;i<(1<<bt1);++i) for(int j=0;j<(1<<bt2);++j) f[i][j]=f[i][j]*1ll*g[i][j]%MOD;
bar(1);
}
int main(){
init();
for(scanf("%d",&T);T--;printf("%d\n",ans),ans=s=lx=rx=ly=ry=0){
scanf("%d%d%d%s",&n,&m,&K,opt+1);len=strlen(opt+1);
for(bt1=1;(1<<bt1)<=n*2;++bt1);
for(bt2=1;(1<<bt2)<=m*2;++bt2);
for(int i=0;i<(1<<bt1);++i) for(int j=0;j<(1<<bt2);++j) f[i][j]=g[i][j]=0;
for(int x=0,y=0,i=1;i<=len;++i){
if(opt[i]=='U') --x;
else if(opt[i]=='D') ++x;
else if(opt[i]=='L') --y;
else ++y;
lx=min(lx,x);rx=max(rx,x);ly=min(ly,y);ry=max(ry,y);
if(x>=-n&&x<=n&&y>=-m&&y<=m) g[x+n][y+m]=1;
}
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(i+rx<=n&&i+lx>=1&&j+ry<=m&&j+ly>=1) f[i][j]=1,++s;
if(s<K) continue;
g[n][m]=1;mult();
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) ans+=(f[i+n][j+m]+K==s);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7696kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
2 20 0
result:
ok 3 number(s): "2 20 0"
Test #2:
score: 0
Accepted
time: 308ms
memory: 14032kb
input:
1060 19 12 0 UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL 11 1 0 UR 3 18 33 UDRLR 17 11 132 RLDRDLDRUU 6 10 13 UULUDDLRDLUUDLDD 1 15 0 D 6 20 50 D...
output:
228 11 20 99 18 15 34 240 15 0 0 13 14 18 26 16 1 19 108 8 2 2 3 7 0 30 16 21 0 8 10 9 15 5 320 11 7 3 0 0 12 0 11 0 0 14 0 22 36 51 23 7 6 4 2 48 28 8 63 22 49 13 10 4 108 10 18 44 0 15 9 0 4 30 14 99 105 10 14 17 0 66 10 11 28 52 34 56 33 14 56 90 14 0 121 3 48 30 36 13 0 30 7 8 3 11 16 45 20 34 0...
result:
ok 1060 numbers
Test #3:
score: 0
Accepted
time: 478ms
memory: 54736kb
input:
1 1000 1000 979065 DDUULULUDULLULLDLUULURRLDURLRDLRRUURUUUDLRLUUDUUDUDLLDDDULU
output:
958416
result:
ok 1 number(s): "958416"
Test #4:
score: 0
Accepted
time: 498ms
memory: 54948kb
input:
1 1000 1000 943471 LRLDLURLDLRDRDUULULRDDLLRURDUURLLDDLDLDDLLLUUURLDRUDRLLUUUUUDLUUDLURURRDLRLRRRLULRRULURLRRDLDRLUDRRLDDLUDRRLLUDLLLRDULRRRRLDUUDRDLULUUUUDRRDULUDLLUUDLDURDRRLRRLDRLDDRURURLUULRRLDLLRLRDRRUULDLDLULLDLLRULLRUULURDURRLUUDUULLULDLRUDDLRLRLLUDDDLLLUDRRLDDULRRURRDURDDRDLLULRLULURLRDLLURD...
output:
889224
result:
ok 1 number(s): "889224"
Test #5:
score: 0
Accepted
time: 502ms
memory: 55868kb
input:
1 1000 1000 315808 LLRURURRDDDULLDDUDRDLRLLLDDDLUDRDURLDULRLRULUUDLUULUUDULLLLDDURLDUULUUDLLDLLDRUDUULRLLRLRUURLRLULLDDLLDUDLLRUUDRLDLUULDLLDRRRURDULLDRRRDURURDRLDURURUDLURLDURRLRRUDUDURDRLRRRDLRRURLURUDRRLDLRULLDLUURDURLURLLRDLRDRUURURDRUDUUUDLRRLUDLUUDUDDRRDUULUUDDRLLULDUUDRURRDRLULRLULDURLURUDLLD...
output:
426
result:
ok 1 number(s): "426"
Test #6:
score: 0
Accepted
time: 480ms
memory: 54852kb
input:
1 1000 1000 986018 LLULDRRRDDURRUDRUURRRDDLUUDUULRULRDULLD
output:
972180
result:
ok 1 number(s): "972180"
Test #7:
score: 0
Accepted
time: 482ms
memory: 54572kb
input:
1 1000 1000 945431 DDRRURUUDLDULLDLDDLRULDLLDDRRLUDRLUURRLDRDLURUURRRRLRURLURULLLDRDDDRRRLDLDRLRDDUURRURDDDLRUURLUURLRDUDDDLLDUURLDLUDLLRRDUUDRLUULLUULDLURRUDLUURLRLRURDUDRRRDRLRUDLLLLURLULRLRLRRDDUDLRLDUUUULUDLLURRLURRDLRURRRULDDLLLRLRDLUDLLDDRULDUULRDDUUDDUDLURDULLDUDDLULRULDRLDDULDULLUDLULUDRURRR...
output:
893000
result:
ok 1 number(s): "893000"
Test #8:
score: 0
Accepted
time: 542ms
memory: 55820kb
input:
1 1000 1000 460035 RDDUURDULDDLDDLDDLDRRULLRLUURLURRRDRUDDDRDLDLDULUDLRLLRRLRRURRRDLRLUDRDURULDRRDDDDDDLRLDULUULDUDRLLUUUURUUDRURLRRULDRDRUUUUULULRURDDRLRULLLRDRRULUDDUDDLLLRDRUULUUDDRLURDLDURRDLRRLDRRUDLUULRDLURULLDLRLLDDURDUDLDULDLLRULRDLRLUULLUDRUDDDLRRDULULLRUURLUURRLLLLRLDRURLLRLDRRDDDRLUUUUDUL...
output:
417
result:
ok 1 number(s): "417"
Test #9:
score: 0
Accepted
time: 528ms
memory: 54812kb
input:
1 1000 1000 992010 LLLLLDLDRRLUDRR
output:
1999
result:
ok 1 number(s): "1999"
Test #10:
score: 0
Accepted
time: 497ms
memory: 54572kb
input:
1 1000 1000 919600 LLDLRUDRLURRUDRDRRDLRUDLRRRUUULDLDURDDDRUURRRLLURULDRLRLULLULDRULULRLRRRURLDDDRUUULUDLLLLRRLLRDDRDULUDLRLRLDRLUDUDURRULUULLDULUULDLLDRDULUDLDULDDUULDDRRURDRDULRRLDRRDUURURRLUUUDRRLDRRDDLULRDDLDLLRLRLLLRULUUUURRRLDLRUDRRLRURDRLDULLLUDRULLDLDRRUUDLRRLLRLDDLUDLRLRRURUUDUULUDURDURRLUU...
output:
944
result:
ok 1 number(s): "944"
Test #11:
score: 0
Accepted
time: 500ms
memory: 56056kb
input:
1 1000 1000 804351 DLRLDLLLLUDRDURRLDDRRLRUULURURDDDRDLRUDDULRRLLULURDRUUDRURRLURRRDRURRDRLULRDLRRDRRDDUDLUDLDULRUURRLRUUDRLDDRDDUUDULUULUUUDLRURULLRDUUDDDRRLDRUDDUUDRURLRDRUDLRLDDRRLLRLRDUDDULLULRLLDDUDDDUULDULLRRULULDUUULUDRRDRLUDLRRDDUDLRRDDLDLDRUULRRRRRLRLULLRDDRDDDULDRRURUDDLURLRLURLRDRULUDULUU...
output:
640000
result:
ok 1 number(s): "640000"