QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#710888#5414. Stop, Yesterday Please No MoreinoaderRE 0ms3728kbC++141.3kb2024-11-04 22:49:462024-11-04 22:49:48

Judging History

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

  • [2024-11-04 22:49:48]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3728kb
  • [2024-11-04 22:49:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
	int x=0,k=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')k=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*k;
}
string s;
int a[1005][1005];
void sol(){
	int n=read(),m=read(),k=read();
	int x1=1,y1=1,x2=n,y2=m;
	cin>>s;
	for(char c:s){
		if(c=='U')x1=max(x1-1,1ll),--x2;
		else if(c=='D')x2=min(x2+1,n),++x1;
		else if(c=='L')y1=max(y1-1,1ll),--y2;
		else y2=min(y2+1,m),++y1;
	}
	int sum=(x2-x1+1)*(y2-y1+1);
	if(sum<0)sum=0;
	if(sum<k){
		puts("0");
		return;
	}
	if(sum==0){
		cout<<n*m<<endl;
		return;
	}
	for(int i=0;i<=n+1;++i)
		for(int j=0;j<=m+1;++j)a[i][j]=0;
	++a[x1][y1],++a[x2+1][y2+1],--a[x1][y2+1],--a[x2+1][y1];
	for(int i=s.length()-1;~i;--i){
		char c=s[i];
		if(c=='U')++x1,++x2;
		else if(c=='D')--x1,--x2;
		else if(c=='L')++y1,++y2;
		else --y1,--y2;
		if(x1<1||x2>n||y1<1||y2>m)while(1);
		++a[x1][y1],++a[x2+1][y2+1],--a[x1][y2+1],--a[x2+1][y1];
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			if(a[i][j]==sum-k)++ans;
		}
	cout<<ans<<endl; 
}
signed main(){
	int T=read();
	while(T--)sol();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3728kb

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
Runtime Error

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:

16
11
17
9
18
15
21
240
14
0
0
5
1
18
3
16
1
31
108
8
1
2
3
7
0
29
4
20
0
8
10
9
6
5
320
3
5
3
0
0
7
0
11
0
0
8
128
22
18
51
23
5
6
3
9
48
28
8
1
22
49
13
10
2
12
6
18
44
0
14
5
0
4
30
14
99
105
2
27
17
0
66
10
11
28
52
32
8
22
14
0
90
15
0
22
3
48
29
20
9
0
30
6
8
3
10
16
45
16
17
0
20
0
21
0
6
0
2...

result: