QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72857#5414. Stop, Yesterday Please No Morechenshi#WA 545ms22280kbC++2.3kb2023-01-19 18:17:562023-01-19 18:17:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-19 18:17:59]
  • 评测
  • 测评结果:WA
  • 用时:545ms
  • 内存:22280kb
  • [2023-01-19 18:17:56]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int o=4100,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;char opt[o];
inline void init(){
	int bt=12;
	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;i<(1<<bt1);++i){
		ntt(f[i],1<<bt2,inv);
		if(inv) for(int j=0,coef=qp(1<<bt2,MOD-2);j<(1<<bt2);++j) f[i][j]=f[i][j]*1ll*coef%MOD;
		else ntt(g[i],1<<bt2,inv);
	}
}
inline void bar(bool inv){
	foo(inv);
	for(int i=0;i<(1<<bt1);++i) for(int j=i+1;j<(1<<bt2);++j) swap(f[i][j],f[j][i]),swap(g[i][j],g[j][i]);
	swap(bt1,bt2);foo(inv);
}
inline void mult(){
	if((1<<bt1)*(1<<bt2)<=32){
		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*3;++bt1);
		for(bt2=1;(1<<bt2)<=m*3;++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>=-n&&y<=n) 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+rx<=m&&j+lx>=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: 1ms
memory: 5712kb

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: -100
Wrong Answer
time: 545ms
memory: 22280kb

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
0
0
0
15
0
0
9
0
0
3
9
18
0
0
0
0
108
0
0
0
0
0
0
30
60
0
0
0
0
0
0
0
6
0
0
0
0
0
0
0
0
0
0
0
0
22
0
0
0
1
6
2
0
9
2
8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
30
0
0
0
0
0
17
0
0
0
0
0
0
0
0
0
0
56
0
0
0
0
0
48
0
0
0
0
30
1
8
0
0
0
0
0
0
0
0
1
0
0
0
0
0
24
48
10
0
225
6
0
0
0
0
0
0
0
0
228
0
30
0
30
8
...

result:

wrong answer 3rd numbers differ - expected: '20', found: '0'