# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954225 |
2024-03-27T13:01:21 Z |
tmtxangel |
Mecho (IOI09_mecho) |
C++17 |
|
164 ms |
11600 KB |
#include <bits/stdc++.h>
#define lli long long
#define ld long double
#define tmt angel
using namespace std;
const int maxn = 802;
int vis[maxn][maxn], n, m;
char a[maxn][maxn];
int tim[maxn][maxn];
int mtim[maxn][maxn];
int hi, hj, sti, stj;
int x[4] = {1, -1, 0, 0};
int y[4] = {0, 0, 1, -1};
deque<pair<pair<int, int>, int>> s;
bool flag = false;
int bvis[maxn][maxn];
bool valid_sq(int nx, int ny) {
return nx >= 0 && nx < n && ny >= 0 && ny < n &&
(a[nx][ny] == 'G' || a[nx][ny] == 'M');
}
void gocheck(int i, int j, int cost)
{
if(i < 1 || j < 1 || i > n || j > n || bvis[i][j] == 1 || a[i][j] == 'D' || a[i][j] == 'T') return;
bvis[i][j] = 1;
tim[i][j] = cost;
s.push_back({{i, j}, cost});
}
void spread(int i, int j, int cost, int st)
{
//if(vis[hi][hj] == 1) return;
if(i < 1 || j < 1 || i > n || j > n || vis[i][j] == 1) return;
if(tim[i][j] - st > cost / m)
{
s.push_back({{i, j}, cost});
vis[i][j] = 1;
mtim[i][j] = cost;
}
}
void Bfs()
{
while(!s.empty())
{
int i = s.front().first.first;
int j = s.front().first.second;
int c = s.front().second;
s.pop_front();
for(int f = 0; f < 4; f++)
{
gocheck(i + x[f], j + y[f], c+1);
}
}
}
bool checked(int st)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
vis[i][j] = a[i][j] == 'G' || a[i][j] == 'D' ? 0 : 1;
mtim[i][j] = 0;
}
}
s.clear();
s.push_back({{sti, stj}, 0});
while(!s.empty())
{
int i = s.front().first.first;
int j = s.front().first.second;
int c = s.front().second;
s.pop_front();
for(int f = 0; f < 4; f++)
{
spread(i + x[f], j + y[f], c+1, st);
//if(vis[hi][hj] == 1) break;
}
}
// if(st == 0) s.push_back({ {sti, stj},{2, 0} });
for(int f = 0; f < 4; f++)
{
int nx = hi + x[f], ny = hj + y[f];
if(valid_sq(nx, ny) && vis[nx][ny] == 1 && mtim[nx][ny] / m < tim[nx][ny] - st) return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".INP", "r" , stdin);
// freopen(".OUT", "w" , stdout);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
if(a[i][j] == 'M' )
{
vis[i][j] = 1;
sti = i;
stj = j;
}
else vis[i][j] = a[i][j] == 'G' || a[i][j] == 'D' ? 0 : 1;
if(a[i][j] == 'D')
{
hi = i;
hj = j;
}
if(a[i][j] == 'H')
{
s.push_back({{i, j}, 0});
bvis[i][j] = 1;
}
}
}
Bfs();
//s.clear();
//cout << checked(1);
int low = 0, high = n*n, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(tim[sti][stj] <= mid) high = mid-1;
if(checked(mid)) low = mid +1;
else high = mid - 1;
}
cout << low-1;
/*for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cout << mtim[i][j] << " ";
}
cout << '\n';
}
cout << '\n';
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cout << tim[i][j] << " ";
}
cout << '\n';
}*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
7 |
Correct |
85 ms |
11296 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6748 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
1 ms |
6748 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
8796 KB |
Output is correct |
26 |
Correct |
1 ms |
7000 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
2 ms |
8796 KB |
Output is correct |
31 |
Correct |
2 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
8796 KB |
Output is correct |
33 |
Correct |
7 ms |
10840 KB |
Output is correct |
34 |
Correct |
8 ms |
9560 KB |
Output is correct |
35 |
Incorrect |
20 ms |
10844 KB |
Output isn't correct |
36 |
Correct |
8 ms |
10844 KB |
Output is correct |
37 |
Correct |
10 ms |
9820 KB |
Output is correct |
38 |
Incorrect |
27 ms |
11040 KB |
Output isn't correct |
39 |
Correct |
9 ms |
10840 KB |
Output is correct |
40 |
Correct |
11 ms |
10076 KB |
Output is correct |
41 |
Incorrect |
34 ms |
10896 KB |
Output isn't correct |
42 |
Correct |
12 ms |
10844 KB |
Output is correct |
43 |
Correct |
13 ms |
10184 KB |
Output is correct |
44 |
Incorrect |
40 ms |
10844 KB |
Output isn't correct |
45 |
Correct |
17 ms |
10844 KB |
Output is correct |
46 |
Correct |
16 ms |
10328 KB |
Output is correct |
47 |
Incorrect |
51 ms |
10844 KB |
Output isn't correct |
48 |
Correct |
17 ms |
10844 KB |
Output is correct |
49 |
Correct |
19 ms |
10476 KB |
Output is correct |
50 |
Incorrect |
62 ms |
10844 KB |
Output isn't correct |
51 |
Correct |
22 ms |
10728 KB |
Output is correct |
52 |
Correct |
22 ms |
10584 KB |
Output is correct |
53 |
Incorrect |
78 ms |
10908 KB |
Output isn't correct |
54 |
Correct |
23 ms |
10844 KB |
Output is correct |
55 |
Correct |
26 ms |
10872 KB |
Output is correct |
56 |
Incorrect |
85 ms |
10844 KB |
Output isn't correct |
57 |
Correct |
33 ms |
10840 KB |
Output is correct |
58 |
Correct |
28 ms |
10844 KB |
Output is correct |
59 |
Incorrect |
131 ms |
11008 KB |
Output isn't correct |
60 |
Correct |
30 ms |
11096 KB |
Output is correct |
61 |
Correct |
31 ms |
11096 KB |
Output is correct |
62 |
Incorrect |
117 ms |
11096 KB |
Output isn't correct |
63 |
Incorrect |
92 ms |
11100 KB |
Output isn't correct |
64 |
Incorrect |
164 ms |
11144 KB |
Output isn't correct |
65 |
Incorrect |
152 ms |
11100 KB |
Output isn't correct |
66 |
Incorrect |
121 ms |
11100 KB |
Output isn't correct |
67 |
Correct |
95 ms |
11100 KB |
Output is correct |
68 |
Incorrect |
57 ms |
11192 KB |
Output isn't correct |
69 |
Incorrect |
56 ms |
11188 KB |
Output isn't correct |
70 |
Incorrect |
47 ms |
11204 KB |
Output isn't correct |
71 |
Incorrect |
45 ms |
11100 KB |
Output isn't correct |
72 |
Incorrect |
69 ms |
11180 KB |
Output isn't correct |
73 |
Incorrect |
47 ms |
11356 KB |
Output isn't correct |
74 |
Correct |
59 ms |
11552 KB |
Output is correct |
75 |
Correct |
71 ms |
11356 KB |
Output is correct |
76 |
Correct |
61 ms |
11356 KB |
Output is correct |
77 |
Correct |
66 ms |
11556 KB |
Output is correct |
78 |
Correct |
75 ms |
11352 KB |
Output is correct |
79 |
Correct |
54 ms |
11392 KB |
Output is correct |
80 |
Correct |
63 ms |
11356 KB |
Output is correct |
81 |
Correct |
70 ms |
11352 KB |
Output is correct |
82 |
Correct |
62 ms |
11352 KB |
Output is correct |
83 |
Correct |
76 ms |
11352 KB |
Output is correct |
84 |
Correct |
66 ms |
11352 KB |
Output is correct |
85 |
Correct |
98 ms |
11448 KB |
Output is correct |
86 |
Correct |
73 ms |
11252 KB |
Output is correct |
87 |
Correct |
70 ms |
11356 KB |
Output is correct |
88 |
Correct |
84 ms |
11600 KB |
Output is correct |
89 |
Correct |
80 ms |
11352 KB |
Output is correct |
90 |
Correct |
75 ms |
11356 KB |
Output is correct |
91 |
Correct |
81 ms |
11356 KB |
Output is correct |
92 |
Correct |
84 ms |
11356 KB |
Output is correct |