QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72862#5414. Stop, Yesterday Please No Morechenshi#WA 590ms32664kbC++2.4kb2023-01-19 18:28:552023-01-19 18:28:56

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:28:56]
  • 评测
  • 测评结果:WA
  • 用时:590ms
  • 内存:32664kb
  • [2023-01-19 18:28:55]
  • 提交

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,tmp[o][o];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,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*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>=-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+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: 2ms
memory: 7936kb

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: 590ms
memory: 32664kb

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
18
0
0
15
34
0
9
0
0
3
9
18
0
15
0
4
108
0
2
2
3
0
1
30
60
0
0
0
10
9
0
0
6
0
5
0
0
0
4
0
0
0
0
0
0
22
0
0
23
1
6
2
0
48
28
8
0
0
0
13
0
0
0
0
2
44
0
0
0
0
0
30
0
0
0
0
0
17
32
66
9
11
28
0
0
0
0
0
56
90
0
0
0
0
48
26
0
0
0
30
1
8
0
6
0
0
0
0
0
38
4
0
0
0
0
0
24
48
10
0
225
36
0
0
0
0
40
90
0...

result:

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