QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236199#5414. Stop, Yesterday Please No MoreqpdkWA 6ms9716kbC++142.7kb2023-11-03 18:05:112023-11-03 18:05:11

Judging History

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

  • [2023-11-03 18:05:11]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:9716kb
  • [2023-11-03 18:05:11]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXL 1001000
#define N 1010
using namespace std;

int t,n,m,k;
int g[N<<1][N<<1],sum[N<<1][N<<1];
int gnmin = 1000, gnmax = 1000, gmmin = 1000, gmmax = 1000;
string s;

inline int query(int x1, int y1, int x2, int y2){
	if(x1>gnmax || y1>gmmax) return -114514;
	return sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1];
}

int main(){
	cin >> t;
	while(t--){
		cin >> n >> m >> k;
		cin >> s;
		
		int nmin = 1, nmax = n, mmin = 1, mmax = m;
		gnmin = 1000, gnmax = 1000, gmmin = 1000, gmmax = 1000;
		int flag = 1;
		
		int x = 0, y = 0;
		int len = s.length();
		for(int i = 0; i < len; i++){
			if(s[i] == 'U'){
				x++;
				nmin = max(nmin, x+1);
			}
			else if(s[i] == 'D'){
				x--;
				nmax = min(nmax, n+x);
			}
			else if(s[i] == 'L'){
				y--;
				mmin = max(mmin, 1-y);
			}
			else if(s[i] == 'R'){
				y++;
				mmax = min(mmax, m-y);
			}
			
			if(nmin>nmax || mmin>mmax){
				flag = 0;
				break;
			}
			
			int xg = 1001+x, yg = 1001-y;
			g[xg][yg] = 1;
			gnmin = min(gnmin, xg);
			gnmax = max(gnmax, xg);
			gmmin = min(gmmin, yg);
			gmmax = max(gmmax, yg);
		}
		g[1001][1001] = 1;
//		printf("nmin=%d nmax=%d mmin=%d mmax=%d\n", nmin, nmax, mmin, mmax);
		
		if(!flag){
			if(k == 0){
				cout << n*m << endl;
			}
			else{
				cout << 0 << endl;
			}
			continue;
		}
		
		for(int i = gnmin-1; i <= gnmax; i++) sum[i][gmmin] = 0;
		for(int j = gmmin-1; j <= gmmax; j++) sum[gnmin][j] = 0;
		for(int i = gnmin; i <= gnmax+nmax; i++){
//			printf("%d : ", i);
			for(int j = gmmin; j <= gmmax+mmax; j++){
				sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + g[i][j];
//				printf("%d ", g[i][j]);
			}
//			printf("\n");
		}
		
		int res = (nmax-nmin+1) * (mmax-mmin+1);
		int com = res - k;
		int ans = 0;
		
//		cout << com << endl;
		
//		cout << query(1000, 1000, 1002, 1002) << endl;
		//		cout << com << endl;
		
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= n; j++){
				int x1 = nmin-i+1+1000;
				int y1 = mmin-j+1+1000;
				int x2 = x1+(nmax-nmin);
				int y2 = y1+(mmax-mmin);
//				printf("i=%d j=%d\n", i, j);
//				printf("x1=%d y1=%d x2=%d y2=%d\n", x1, y1, x2, y2);
//				printf("query = %d\n\n", query(x1, y1, x2, y2));
				if(query(x1, y1, x2, y2) == com){
					ans++;
//					cout << "HHHHHH" << endl;
				}
			}
		}
		
		cout << ans << endl;
		
		// clear!!
		for(int i = gnmin-1; i <= gnmax+nmax; i++){
			for(int j = gmmin-1; j <= gmmax+mmax; j++){
				g[i][j] = 0;
				sum[i][j] = 0;
			}
		}
	}
	
	return 0;
}

/*
3
4 5 3
ULDDRR
4 5 0
UUUUUUU
4 5 10
UUUUUUU
 */

/*
  
1
6 7 16
URUDRDL
 */

详细

Test #1:

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

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: 6ms
memory: 9716kb

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

result:

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