QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72870#5414. Stop, Yesterday Please No Morechenshi#TL 933ms29924kbC++2.4kb2023-01-19 19:07:182023-01-19 19:07:21

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 19:07:21]
  • 评测
  • 测评结果:TL
  • 用时:933ms
  • 内存:29924kb
  • [2023-01-19 19:07:18]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int o=4100,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=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+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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7904kb

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: 933ms
memory: 29924kb

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: -100
Time Limit Exceeded

input:

1
1000 1000 979065
DDUULULUDULLULLDLUULURRLDURLRDLRRUURUUUDLRLUUDUUDUDLLDDDULU

output:


result: