# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
882608 |
2023-12-03T12:14:08 Z |
qrupafjzvm1 |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
65536 KB |
//memset 0x3f -> > 1000000000
#include <bits/stdc++.h>
#define f first
#define s second
#define MAXSIZE (int)(2e5+5)
// #define int long long
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef pair<int,int> ii;
string answerString[2] = {"NO", "YES"};
int add(int x, int y, int mod)
{
int t = x + y;
return t - mod * (t>=mod);
}
int sub(int x, int y, int mod)
{
int t = x - y;
return t + mod * (t<0);
}
int xd[4] = {0,0,1,-1}, yd[4] = {1,-1,0,0};
int d[808][808];
char c[808][808];
bool ch[808][808];
int mx, my, dx, dy, n, s;
vector <ii> hives;
void bfs()
{
queue <ii> q;
memset(d,0x3f,sizeof(d));
for (ii h : hives) {q.push(h); d[h.f][h.s] = 0;}
while (!q.empty())
{
ii u = q.front(); q.pop();
for (int i=0;i<4;i++)
{
ii v = {u.f + xd[i], u.s + yd[i]};
if (v.f>=1 && v.f<=n && v.s>=1 && v.s<=n
&& c[v.f][v.s] != 'T' && d[v.f][v.s]>d[u.f][u.s]+1)
{
d[v.f][v.s] = d[u.f][u.s] + 1;
q.push(v);
}
}
}
}
void dfs(ii u, int dt, int cnt)
{
ch[u.f][u.s] = true;
for (int i=0;i<4;i++)
{
ii v = {u.f + xd[i], u.s + yd[i]};
if (v.f>=1 && v.f<=n && v.s>=1 && v.s<=n
&& c[v.f][v.s] != 'T' && dt+(cnt==0)<d[v.f][v.s])
{
if (cnt==0) dfs(v,dt+1,s-1);
else dfs(v,dt,cnt-1);
}
}
}
signed main()
{
//freopen("mecho.inp","r",stdin);
//freopen("text.out","w",stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>s;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
cin>>c[i][j];
if (c[i][j]=='M') {mx = i, my = j;}
if (c[i][j]=='D') {dx = i, dy = j;}
if (c[i][j]=='H') hives.push_back({i,j});
}
bfs();
/*for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++) cout<<d[i][j]<<" ";
cout<<endl;
}*/
int l = -1, r = n*n+1, ans = -1;
while (r-l>1)
{
//cout<<l<<" "<<r<<endl;
memset(ch,0,sizeof(ch));
int m = (l + r) / 2; dfs({mx, my}, m, s);
if (ch[dx][dy]) l = ans = m;
else r = m;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4184 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4184 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4188 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
4232 KB |
Output isn't correct |
5 |
Execution timed out |
1066 ms |
4188 KB |
Time limit exceeded |
6 |
Execution timed out |
1045 ms |
4188 KB |
Time limit exceeded |
7 |
Execution timed out |
1052 ms |
5116 KB |
Time limit exceeded |
8 |
Incorrect |
2 ms |
4188 KB |
Output isn't correct |
9 |
Execution timed out |
1087 ms |
4188 KB |
Time limit exceeded |
10 |
Correct |
88 ms |
4308 KB |
Output is correct |
11 |
Correct |
138 ms |
4280 KB |
Output is correct |
12 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
13 |
Execution timed out |
1035 ms |
4188 KB |
Time limit exceeded |
14 |
Execution timed out |
1037 ms |
4184 KB |
Time limit exceeded |
15 |
Execution timed out |
1059 ms |
4188 KB |
Time limit exceeded |
16 |
Execution timed out |
1064 ms |
4188 KB |
Time limit exceeded |
17 |
Execution timed out |
1018 ms |
4184 KB |
Time limit exceeded |
18 |
Execution timed out |
1034 ms |
4184 KB |
Time limit exceeded |
19 |
Execution timed out |
1033 ms |
4192 KB |
Time limit exceeded |
20 |
Execution timed out |
1090 ms |
4304 KB |
Time limit exceeded |
21 |
Execution timed out |
1027 ms |
4188 KB |
Time limit exceeded |
22 |
Execution timed out |
1047 ms |
4440 KB |
Time limit exceeded |
23 |
Execution timed out |
1045 ms |
4188 KB |
Time limit exceeded |
24 |
Execution timed out |
1026 ms |
4816 KB |
Time limit exceeded |
25 |
Execution timed out |
1058 ms |
4188 KB |
Time limit exceeded |
26 |
Execution timed out |
1036 ms |
5208 KB |
Time limit exceeded |
27 |
Execution timed out |
1037 ms |
4188 KB |
Time limit exceeded |
28 |
Execution timed out |
1065 ms |
5468 KB |
Time limit exceeded |
29 |
Execution timed out |
1041 ms |
4184 KB |
Time limit exceeded |
30 |
Execution timed out |
1099 ms |
5720 KB |
Time limit exceeded |
31 |
Execution timed out |
1058 ms |
4188 KB |
Time limit exceeded |
32 |
Execution timed out |
1039 ms |
5980 KB |
Time limit exceeded |
33 |
Execution timed out |
1012 ms |
6744 KB |
Time limit exceeded |
34 |
Runtime error |
44 ms |
65536 KB |
Execution killed with signal 9 |
35 |
Execution timed out |
1063 ms |
15456 KB |
Time limit exceeded |
36 |
Execution timed out |
1092 ms |
7512 KB |
Time limit exceeded |
37 |
Runtime error |
50 ms |
65536 KB |
Execution killed with signal 9 |
38 |
Execution timed out |
1049 ms |
18264 KB |
Time limit exceeded |
39 |
Execution timed out |
1056 ms |
8284 KB |
Time limit exceeded |
40 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
41 |
Execution timed out |
1010 ms |
21116 KB |
Time limit exceeded |
42 |
Execution timed out |
1031 ms |
9292 KB |
Time limit exceeded |
43 |
Runtime error |
44 ms |
65536 KB |
Execution killed with signal 9 |
44 |
Execution timed out |
1058 ms |
24156 KB |
Time limit exceeded |
45 |
Execution timed out |
1035 ms |
10240 KB |
Time limit exceeded |
46 |
Runtime error |
45 ms |
65536 KB |
Execution killed with signal 9 |
47 |
Execution timed out |
1016 ms |
33504 KB |
Time limit exceeded |
48 |
Execution timed out |
1032 ms |
11588 KB |
Time limit exceeded |
49 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
50 |
Execution timed out |
1095 ms |
38452 KB |
Time limit exceeded |
51 |
Execution timed out |
1067 ms |
12872 KB |
Time limit exceeded |
52 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
53 |
Execution timed out |
1092 ms |
43616 KB |
Time limit exceeded |
54 |
Execution timed out |
1056 ms |
14164 KB |
Time limit exceeded |
55 |
Runtime error |
51 ms |
65536 KB |
Execution killed with signal 9 |
56 |
Execution timed out |
1080 ms |
48980 KB |
Time limit exceeded |
57 |
Execution timed out |
1037 ms |
15692 KB |
Time limit exceeded |
58 |
Runtime error |
46 ms |
65536 KB |
Execution killed with signal 9 |
59 |
Execution timed out |
1056 ms |
54588 KB |
Time limit exceeded |
60 |
Execution timed out |
1065 ms |
17236 KB |
Time limit exceeded |
61 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
62 |
Execution timed out |
1029 ms |
60240 KB |
Time limit exceeded |
63 |
Execution timed out |
1059 ms |
4956 KB |
Time limit exceeded |
64 |
Execution timed out |
1074 ms |
9780 KB |
Time limit exceeded |
65 |
Execution timed out |
1020 ms |
4700 KB |
Time limit exceeded |
66 |
Execution timed out |
1051 ms |
4956 KB |
Time limit exceeded |
67 |
Execution timed out |
1045 ms |
4744 KB |
Time limit exceeded |
68 |
Execution timed out |
1049 ms |
5204 KB |
Time limit exceeded |
69 |
Execution timed out |
1059 ms |
7508 KB |
Time limit exceeded |
70 |
Execution timed out |
1048 ms |
4924 KB |
Time limit exceeded |
71 |
Execution timed out |
1056 ms |
4956 KB |
Time limit exceeded |
72 |
Execution timed out |
1042 ms |
7336 KB |
Time limit exceeded |
73 |
Execution timed out |
1057 ms |
5204 KB |
Time limit exceeded |
74 |
Execution timed out |
1048 ms |
9040 KB |
Time limit exceeded |
75 |
Execution timed out |
1036 ms |
5052 KB |
Time limit exceeded |
76 |
Execution timed out |
1042 ms |
5200 KB |
Time limit exceeded |
77 |
Execution timed out |
1022 ms |
5204 KB |
Time limit exceeded |
78 |
Execution timed out |
1052 ms |
5200 KB |
Time limit exceeded |
79 |
Execution timed out |
1057 ms |
8848 KB |
Time limit exceeded |
80 |
Execution timed out |
1068 ms |
5204 KB |
Time limit exceeded |
81 |
Execution timed out |
1068 ms |
5220 KB |
Time limit exceeded |
82 |
Execution timed out |
1071 ms |
5364 KB |
Time limit exceeded |
83 |
Execution timed out |
1064 ms |
5212 KB |
Time limit exceeded |
84 |
Execution timed out |
1065 ms |
9812 KB |
Time limit exceeded |
85 |
Execution timed out |
1036 ms |
4956 KB |
Time limit exceeded |
86 |
Execution timed out |
1004 ms |
5208 KB |
Time limit exceeded |
87 |
Execution timed out |
1026 ms |
5456 KB |
Time limit exceeded |
88 |
Execution timed out |
1030 ms |
5208 KB |
Time limit exceeded |
89 |
Execution timed out |
1032 ms |
11100 KB |
Time limit exceeded |
90 |
Execution timed out |
1072 ms |
5204 KB |
Time limit exceeded |
91 |
Execution timed out |
1055 ms |
5684 KB |
Time limit exceeded |
92 |
Execution timed out |
1046 ms |
5208 KB |
Time limit exceeded |