# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
763917 |
2023-06-23T03:13:20 Z |
hanlulu |
Mecho (IOI09_mecho) |
C++14 |
|
161 ms |
6172 KB |
//https://cses.fi/problemset/task/1707
#include <bits/stdc++.h>
using namespace std;
/*
有点像793的题目,两次最短。Bee走出到每一个位置的最短,
然后二分答案,然后Mecho走最短的时侯每一个相邻是否可以走需要计算是否Bee先到。
如何处理一分钟走s步这里?dis记录当前的步数,每次走到相邻+1,但是时间可以用dis/s得到。
注意:一个位置如果bee先到,比如2s到,m 3s到,那么m就不能走,如果相等可以走,因为每一次都是m先走。
但是,终点要特殊处理。 能到达终点的周围四个点就可以到达。
*/
int n,s;
char a[801][801];
int rdir[4] = {0,0,1,-1};
int cdir[4] = {1,-1,0,0};
vector<vector<int>> beetime(801,vector<int>(801,1e9));
int sx,sy,ex,ey;//起点和终点
bool isok(int eat)//eat is how many time he stay at start point.
{
if (eat >= beetime[sx][sy]) return false;
vector<vector<int>> mstep(801,vector<int>(801,1e9));
//cout << eat << endl;
queue<pair<int,int>> myq;
mstep[sx][sy] = 0;
myq.push({sx,sy});
while (!myq.empty()) {
int x = myq.front().first;
int y = myq.front().second;
myq.pop();
for (int i = 0; i < 4; i++)
{
int newx = x + rdir[i];
int newy = y + cdir[i];
if (a[newx][newy] == 'D') return true;//终点不需要判断了。因为bee到不了。
if (newx <0 || newx == n || newy < 0 || newy == n) continue;
if (a[newx][newy] == 'T' || a[newx][newy] == 'H' ) continue;
if (mstep[newx][newy] <= mstep[x][y] + 1) continue;
//if (beetime[newx][newy] < ceil(1.0*(mstep[x][y]+1) /s) + eat) continue;
if (beetime[newx][newy] <= (mstep[x][y]+1) /s + eat) continue;
//cout << newx << " " << newy << " " << (mstep[x][y]+1) /s + eat << endl;
mstep[newx][newy] = mstep[x][y] + 1;
myq.push({newx,newy});
}
}
//cout << mstep[2][2] << endl;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("nocross.in","r",stdin);
//freopen("nocross.out","w",stdout);
cin >> n >> s;
queue<pair<int,int>> myq;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
if (a[i][j] == 'M') sx = i, sy = j;
if (a[i][j] == 'D') ex = i, ey = j;
if (a[i][j] == 'H') {
beetime[i][j] = 0;
myq.push({i,j});
};
}
//find beetime
while (!myq.empty()) {
int x = myq.front().first;
int y = myq.front().second;
myq.pop();
for (int i = 0; i < 4; i++)
{
int newx = x + rdir[i];
int newy = y + cdir[i];
if (newx <0 || newx == n || newy < 0 || newy == n) continue;
if (a[newx][newy] == 'T' || a[newx][newy] == 'H' || a[newx][newy] == 'D') continue;
if (beetime[newx][newy] <= beetime[x][y] + 1) continue;
beetime[newx][newy] = beetime[x][y] + 1;
myq.push({newx,newy});
}
}
// cout << beetime[2][2]<< endl;
//bin the answer
int ans = -1;
int l = 0, r = n*n, mid;
while (l <= r) {
mid = (l+r)/2;
//cout << "mid " << mid << endl;
if (isok(mid)) {
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5372 KB |
Output is correct |
2 |
Correct |
4 ms |
5392 KB |
Output is correct |
3 |
Correct |
4 ms |
5356 KB |
Output is correct |
4 |
Correct |
4 ms |
5332 KB |
Output is correct |
5 |
Correct |
3 ms |
5352 KB |
Output is correct |
6 |
Correct |
4 ms |
5392 KB |
Output is correct |
7 |
Correct |
80 ms |
6048 KB |
Output is correct |
8 |
Correct |
4 ms |
5372 KB |
Output is correct |
9 |
Correct |
4 ms |
5372 KB |
Output is correct |
10 |
Correct |
4 ms |
5392 KB |
Output is correct |
11 |
Correct |
3 ms |
5352 KB |
Output is correct |
12 |
Correct |
4 ms |
5392 KB |
Output is correct |
13 |
Correct |
2 ms |
5332 KB |
Output is correct |
14 |
Correct |
5 ms |
5448 KB |
Output is correct |
15 |
Correct |
6 ms |
5432 KB |
Output is correct |
16 |
Correct |
4 ms |
5392 KB |
Output is correct |
17 |
Correct |
7 ms |
5464 KB |
Output is correct |
18 |
Correct |
5 ms |
5432 KB |
Output is correct |
19 |
Correct |
6 ms |
5440 KB |
Output is correct |
20 |
Correct |
4 ms |
5392 KB |
Output is correct |
21 |
Correct |
7 ms |
5472 KB |
Output is correct |
22 |
Correct |
6 ms |
5452 KB |
Output is correct |
23 |
Correct |
6 ms |
5452 KB |
Output is correct |
24 |
Correct |
5 ms |
5432 KB |
Output is correct |
25 |
Correct |
7 ms |
5472 KB |
Output is correct |
26 |
Correct |
7 ms |
5492 KB |
Output is correct |
27 |
Correct |
6 ms |
5472 KB |
Output is correct |
28 |
Correct |
8 ms |
5492 KB |
Output is correct |
29 |
Correct |
7 ms |
5472 KB |
Output is correct |
30 |
Correct |
8 ms |
5460 KB |
Output is correct |
31 |
Correct |
7 ms |
5472 KB |
Output is correct |
32 |
Correct |
8 ms |
5472 KB |
Output is correct |
33 |
Correct |
15 ms |
5728 KB |
Output is correct |
34 |
Correct |
10 ms |
5688 KB |
Output is correct |
35 |
Correct |
25 ms |
5700 KB |
Output is correct |
36 |
Correct |
15 ms |
5748 KB |
Output is correct |
37 |
Correct |
13 ms |
5760 KB |
Output is correct |
38 |
Correct |
28 ms |
5732 KB |
Output is correct |
39 |
Correct |
12 ms |
5764 KB |
Output is correct |
40 |
Correct |
15 ms |
5808 KB |
Output is correct |
41 |
Correct |
38 ms |
5760 KB |
Output is correct |
42 |
Correct |
17 ms |
5908 KB |
Output is correct |
43 |
Correct |
15 ms |
5832 KB |
Output is correct |
44 |
Correct |
55 ms |
5760 KB |
Output is correct |
45 |
Correct |
16 ms |
5868 KB |
Output is correct |
46 |
Correct |
14 ms |
5856 KB |
Output is correct |
47 |
Correct |
50 ms |
5844 KB |
Output is correct |
48 |
Correct |
16 ms |
5916 KB |
Output is correct |
49 |
Correct |
15 ms |
5896 KB |
Output is correct |
50 |
Correct |
59 ms |
5836 KB |
Output is correct |
51 |
Correct |
17 ms |
5992 KB |
Output is correct |
52 |
Correct |
17 ms |
5944 KB |
Output is correct |
53 |
Correct |
78 ms |
5920 KB |
Output is correct |
54 |
Correct |
19 ms |
6004 KB |
Output is correct |
55 |
Correct |
24 ms |
6028 KB |
Output is correct |
56 |
Correct |
83 ms |
5968 KB |
Output is correct |
57 |
Correct |
25 ms |
6028 KB |
Output is correct |
58 |
Correct |
21 ms |
6104 KB |
Output is correct |
59 |
Correct |
105 ms |
6128 KB |
Output is correct |
60 |
Correct |
21 ms |
6084 KB |
Output is correct |
61 |
Correct |
20 ms |
6056 KB |
Output is correct |
62 |
Correct |
107 ms |
6008 KB |
Output is correct |
63 |
Correct |
93 ms |
6032 KB |
Output is correct |
64 |
Correct |
161 ms |
6024 KB |
Output is correct |
65 |
Correct |
132 ms |
6136 KB |
Output is correct |
66 |
Correct |
103 ms |
6036 KB |
Output is correct |
67 |
Correct |
98 ms |
6040 KB |
Output is correct |
68 |
Correct |
43 ms |
6052 KB |
Output is correct |
69 |
Correct |
42 ms |
6024 KB |
Output is correct |
70 |
Correct |
34 ms |
6052 KB |
Output is correct |
71 |
Correct |
38 ms |
6060 KB |
Output is correct |
72 |
Correct |
30 ms |
6032 KB |
Output is correct |
73 |
Correct |
30 ms |
5944 KB |
Output is correct |
74 |
Correct |
55 ms |
6076 KB |
Output is correct |
75 |
Correct |
68 ms |
6064 KB |
Output is correct |
76 |
Correct |
61 ms |
6060 KB |
Output is correct |
77 |
Correct |
59 ms |
6080 KB |
Output is correct |
78 |
Correct |
74 ms |
6072 KB |
Output is correct |
79 |
Correct |
45 ms |
6076 KB |
Output is correct |
80 |
Correct |
56 ms |
6056 KB |
Output is correct |
81 |
Correct |
63 ms |
6080 KB |
Output is correct |
82 |
Correct |
56 ms |
6052 KB |
Output is correct |
83 |
Correct |
75 ms |
6056 KB |
Output is correct |
84 |
Correct |
64 ms |
6072 KB |
Output is correct |
85 |
Correct |
78 ms |
6172 KB |
Output is correct |
86 |
Correct |
71 ms |
6084 KB |
Output is correct |
87 |
Correct |
71 ms |
6064 KB |
Output is correct |
88 |
Correct |
77 ms |
6028 KB |
Output is correct |
89 |
Correct |
74 ms |
6052 KB |
Output is correct |
90 |
Correct |
81 ms |
6048 KB |
Output is correct |
91 |
Correct |
96 ms |
6104 KB |
Output is correct |
92 |
Correct |
81 ms |
6048 KB |
Output is correct |