UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202574#3541. 探险smallstone1006279ms222992kbC++112.1kb2024-02-16 10:40:142024-02-16 12:38:10

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//using LL = __int128
#define pii pair<int, int>
#define fi first
#define se second
int n, q, t[200010];
int rep[1000];
int dp[310][310][310], vis[310][310], able[310][310][310];
char s[310][310], r[310];
void read(){
	memset(r, ' ', sizeof r);
	while(r[1] == ' ' || r[1] == '\n' || r[1] == '\0')
		scanf("%s", r + 1);
}
void bfs(int w){
	memset(vis, 0, sizeof vis);
	deque<pii> q;
	q.push_back({1, 1});
	dp[w][1][1] = !!able[w][1][1];
	vis[1][1] = true;
	while(q.size()){
		pii u = q.front();
		q.pop_front();
		int x = u.fi, y = u.se;
		//cout << x << " " << y << "\n";
		for(int xx = max(x - 1, 1) ; xx <= x + 1 && xx <= n ; xx++)
			for(int yy = max(1, y - (xx == x)) ; yy <= y + (xx == x) && yy <= n ; yy++){
				if(!vis[xx][yy]){
					vis[xx][yy] = true;
					dp[w][xx][yy] = dp[w][x][y] + !!able[w][xx][yy];
					if(!!able[w][xx][yy])
						q.push_back({xx, yy});
					else
						q.push_front({xx, yy});
				}
			}
	}
}
int main(){
	scanf("%d%d", &n, &q);
	for(int i = 1 ; i <= n ; i++){
		read();
		copy(r + 1, r + n + 1, s[i] + 1);
	}
	rep['L'] = 1;
	rep['D'] = 2;
	rep['R'] = 4;
	rep['U'] = 8;
	/*
	for(int i = 1 ; i <= n ; i++)
		for(int j = 1 ; j <= n ; j++)
			printf("%c%c", s[i][j], " \n"[j == n]);
	//*/
	for(int i = 1 ; i <= n ; i++)
		for(int j = 1 ; j <= n ; j++){
			able[1][i][j] = rep[s[i][j]];
			//dp[1][i][j] = able[1][j][j] + min();
		}
	for(int k = 2 ; k <= n ; k++)
		for(int i = 1 ; i <= n ; i++)
			for(int j = 1 ; j <= n ; j++){
				able[k][i][j] |= (able[k - 1][i][j + 1] & 1) | (able[k - 1][i + 1][j] & 8) | (able[k - 1][i][j - 1] & 4) | (able[k - 1][i - 1][j] & 2);
				able[k][i][j] |= able[k - 1][i][j ];
			}
	/*
	for(int k = 2 ; k <= n ; k++)
		for(int i = 1 ; i <= n ; i++)
			for(int j = 1 ; j <= n ; j++)
				printf("%lld%c", able[k][i][j], " \n"[j == n]);
	//*/
	for(int i = 1 ; i <= n ; i++)
		bfs(i);
	for(int i = 1 ; i <= q ; i++){
		scanf("%lld", t + i);
		t[i] = min(t[i], n);
		printf("%lld\n", dp[t[i]][n][n]);
	}
	return 0;
}
/*
5 3
....L
..D..
.....
R..U.
.....
1
3
6
*/

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1716kb

input:

5 5
U.D.R
UDL..
.....
...LR
.DU.D
1
2
3
4
5

output:

4
4
4
4
4

result:

ok 5 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1712kb

input:

5 5
.D..L
..L..
R.R..
U..D.
..R.L
1
2
3
4
5

output:

2
3
5
6
6

result:

ok 5 lines

Test #3:

score: 10
Accepted
time: 60ms
memory: 27332kb

input:

100 200000
RU.RRUL...D...DLD.......L.......D.D.L.RL..L.LU....R......U..RL...ULDD.L.UDR.UR.R.U..R..R....

output:

4
27
54
81
102
116
129
140
150
161
167
173
178
180
183
186
188
189
189
191
192
192
192
193
194
195
1...

result:

ok 200000 lines

Test #4:

score: 10
Accepted
time: 73ms
memory: 27332kb

input:

100 200000
..........L.U..R.....R.....U...U..L..U..ULLUR..L.LD.LDU..L.U...D.LDRR...RL..RLLR.ULDR..LD...

output:

3
28
62
89
108
127
139
153
160
166
170
176
179
181
187
189
192
193
194
194
195
195
196
196
196
196
1...

result:

ok 200000 lines

Test #5:

score: 10
Accepted
time: 909ms
memory: 222208kb

input:

300 1
...L...R..LU.....R....D.DLD...R....................D....L.......R........L......L.........D......

output:

599

result:

ok single line: '599'

Test #6:

score: 10
Accepted
time: 1287ms
memory: 222212kb

input:

300 1
..R..............U.R......L.R........D.................UDUU........RL.......D....................

output:

599

result:

ok single line: '599'

Test #7:

score: 10
Accepted
time: 909ms
memory: 222988kb

input:

300 200000
R...R............................RR..R.R....R......................R....R..........R........

output:

1
2
3
6
7
9
16
32
48
72
88
109
128
140
164
183
200
218
230
238
250
260
269
278
289
296
304
318
328
3...

result:

ok 200000 lines

Test #8:

score: 10
Accepted
time: 885ms
memory: 222988kb

input:

300 200000
R..................R.R...........R.R...R.......R.......R.....................R.......RR.....

output:

1
2
3
5
6
11
17
36
53
78
92
118
139
161
179
198
209
223
235
245
253
267
279
286
294
302
312
319
328
...

result:

ok 200000 lines

Test #9:

score: 10
Accepted
time: 952ms
memory: 222988kb

input:

300 200000
R.......................................D.....................U..........R...L.....U........

output:

1
1
1
1
1
1
2
4
5
10
20
24
32
41
46
54
65
76
80
90
98
106
112
121
127
132
138
147
156
160
164
168
17...

result:

ok 200000 lines

Test #10:

score: 10
Accepted
time: 1204ms
memory: 222992kb

input:

300 200000
..L..R..........................D..............D.............U..............R...............

output:

0
0
1
1
1
6
18
37
50
58
81
97
119
131
140
156
174
191
202
217
226
238
245
257
265
270
277
291
301
31...

result:

ok 200000 lines

Extra Test:

score: 0
Extra Test Passed