QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155440#5414. Stop, Yesterday Please No MorelinninsWA 3ms11972kbC++142.1kb2023-09-01 17:02:232023-09-01 17:02:25

Judging History

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

  • [2023-09-01 17:02:25]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11972kb
  • [2023-09-01 17:02:23]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 1e3 + 5;

int mp[N * 2][N * 2],sum[N * 2][N * 2];
char c[N * N];
int T,n,m,k,x,y,mu,md,ml,mr,nud,nlr,ans;

int main()
{
	scanf("%d",&T);
	while(T --)
	{
		scanf("%d%d%d",&n,&m,&k);
		scanf(" %s",c);
		int len = strlen(c);
		mu = md = ml = mr = 0;
		nud = nlr = 0;
		for(int i = 0;i < len;i ++)
		{
			if(c[i] == 'U') nud --;
			else if(c[i] == 'D') nud ++;
			else if(c[i] == 'L') nlr --;
			else if(c[i] == 'R') nlr ++;
			if(nud > 0) md = max(md,nud);
			else mu = max(mu,-nud);
			if(nlr > 0) mr = max(mr,nlr);
			else ml = max(ml,-nlr);
		}
		//printf("mu = %d md = %d ml = %d mr = %d\n",mu,md,ml,mr);
		int lst = max(n - md - mu,0) * max(m - ml - mr,0);
		//printf("lst = %d\n",lst);
		if(lst < k)
		{
			printf("0\n");
		}
		else if(lst == k && k == 0)
		{
			printf("%d\n",n * m);
		}
		else
		{
			ans = 0;
			x = N, y = N;
			for(int i = N - n - 1;i <= N + n + 1;i ++)
			{
				for(int j = N - m - 1;j <= N + m + 1;j ++)
				{
					mp[i][j] = 0;
				}
			}
			for(int i = N - n - 2;i <= N + n + 2;i ++)
			{
				for(int j = N - m - 2;j <= N + m + 2;j ++)
				{
					sum[i][j] = 0;
				}
			}
			mp[N][N] = 1;
			for(int i = 0;i < len;i ++)
			{
				if(c[i] == 'U')
					x ++;
				else if(c[i] == 'D')
					x --;
				else if(c[i] == 'L')
					y ++;
				else if(c[i] == 'R')
					y --;
				mp[x][y] = 1;
			}
			//printf("***\n");
			for(int i = N - n - 1;i <= N + n + 1;i ++)
			{
				for(int j = N - m - 1;j <= N + m + 1;j ++)
				{
					sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mp[i][j];
					//printf("%d ",mp[i][j]);
				}
				//printf("\n");
			}
			//printf("***\n");
			x = n - mu - md; y = m - ml - mr;
			for(int i = N - md;i <= N + n - md - 1;i ++)
			{
				for(int j = N - mr;j <= N + n - mr - 1;j ++)
				{
					if(sum[i][j] - sum[i - x][j] - sum[i][j - y] + sum[i - x][j - y] == lst - k) ans ++;
				}
			}
			printf("%d\n",ans);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3ms
memory: 11972kb

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
4
99
10
15
8
240
15
0
0
13
14
18
26
2
8
4
108
8
1
1
3
7
0
16
11
24
0
9
10
9
15
0
320
11
1
4
0
0
12
0
18
2
0
14
0
22
36
51
17
7
6
2
2
48
28
8
63
22
49
1
10
2
108
4
4
44
0
16
9
0
4
30
14
63
105
10
14
17
0
66
3
11
28
57
12
62
9
7
56
90
14
0
121
0
48
10
39
13
0
30
3
8
3
5
22
45
20
34
0
5
0
8
0
3
...

result:

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