# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1012855 |
2024-07-02T17:39:12 Z |
EkinOnal |
Mecho (IOI09_mecho) |
C++17 |
|
487 ms |
12368 KB |
//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
//#include <cstdio>
//#include <iostream>
using namespace std;
#define MAX 100000007
#define pb push_back
//#define mp make_pair
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>>
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first : key
// myMap.begin()->second : value
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;ans%=mod;a%=mod;b>>=1;}return ans%mod;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int n,s;
vector<vector<char>> grid(1000,vector<char>(1000));
bool valid_sq(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < n &&
(grid[x][y] == 'G' || grid[x][y] == 'M');
}
bool mecho_reached(int mecho_dis, int bees_dis) {
return mecho_dis / s < bees_dis;
}
void solve() {
cin >> n >> s;
pii bear,home;
vector<pii> hives;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin >> grid[i][j];
if(grid[i][j]=='H') hives.pb({i,j});
if(grid[i][j]=='M') bear = {i,j};
if(grid[i][j]=='D') home = {i,j};
}
}
int l=0,r=n*n;
while(l<=r)
{
vector<vector<int>> d(n+2,vector<int>(n+2,INF));
queue<pii> q;
for(int i=0;i<hives.size();i++)
{
q.push({hives[i]});
d[hives[i].f][hives[i].s]=0;
}
while(q.size())
{
int x = q.front().first, y = q.front().second;
q.pop();
for (int i=0;i<4;i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (valid_sq(nx, ny) && d[nx][ny]==INF)
{
d[nx][ny] = d[x][y] + 1;
q.push({nx, ny});
}
}
}
int time = (l+r)/2;
// queue<pii> q;
q = queue<pii>();
vector<vi> dbear(n+2,vi(n+2,INF));
q.push(bear);
dbear[bear.f][bear.s]=0;
while(q.size())
{
int x = q.front().first, y = q.front().second;
q.pop();
for (int i=0;i<4;i++)
{
int nx=x+dx[i],ny=y+dy[i];
if (valid_sq(nx, ny) && dbear[nx][ny]==INF &&mecho_reached(dbear[x][y]+1,d[nx][ny]-time))
{
q.push({nx, ny});
dbear[nx][ny] = dbear[x][y] + 1;
}
}
}
bool flag = false;
for (int i = 0; i < 4; i++)
{
int nx = home.f + dx[i], ny = home.s + dy[i];
if (valid_sq(nx, ny) &&mecho_reached(dbear[nx][ny],d[nx][ny]-time) && dbear[nx][ny]!=INF) flag = true;
}
if (flag) l = time + 1;
else r = time - 1;
}
cout << l-1 << endl;
return;
}
int32_t main() {
// freopen("lasers.in", "r", stdin);
// freopen("lasers.out", "w", stdout);
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
Compilation message
mecho.cpp: In function 'void solve()':
mecho.cpp:68:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=0;i<hives.size();i++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1240 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1464 KB |
Output is correct |
7 |
Correct |
338 ms |
12264 KB |
Output is correct |
8 |
Correct |
1 ms |
1368 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
2 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
14 |
Correct |
2 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1372 KB |
Output is correct |
16 |
Correct |
1 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1372 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1372 KB |
Output is correct |
26 |
Correct |
2 ms |
1372 KB |
Output is correct |
27 |
Correct |
2 ms |
1492 KB |
Output is correct |
28 |
Correct |
2 ms |
1372 KB |
Output is correct |
29 |
Correct |
2 ms |
1372 KB |
Output is correct |
30 |
Correct |
2 ms |
1372 KB |
Output is correct |
31 |
Correct |
2 ms |
1372 KB |
Output is correct |
32 |
Correct |
2 ms |
1464 KB |
Output is correct |
33 |
Correct |
38 ms |
3548 KB |
Output is correct |
34 |
Correct |
30 ms |
3580 KB |
Output is correct |
35 |
Correct |
52 ms |
3604 KB |
Output is correct |
36 |
Correct |
42 ms |
4232 KB |
Output is correct |
37 |
Correct |
39 ms |
4240 KB |
Output is correct |
38 |
Correct |
70 ms |
4188 KB |
Output is correct |
39 |
Correct |
54 ms |
4932 KB |
Output is correct |
40 |
Correct |
68 ms |
4980 KB |
Output is correct |
41 |
Correct |
86 ms |
4920 KB |
Output is correct |
42 |
Correct |
72 ms |
5708 KB |
Output is correct |
43 |
Correct |
64 ms |
5732 KB |
Output is correct |
44 |
Correct |
105 ms |
5704 KB |
Output is correct |
45 |
Correct |
89 ms |
6792 KB |
Output is correct |
46 |
Correct |
75 ms |
6608 KB |
Output is correct |
47 |
Correct |
125 ms |
6572 KB |
Output is correct |
48 |
Correct |
99 ms |
7576 KB |
Output is correct |
49 |
Correct |
99 ms |
7732 KB |
Output is correct |
50 |
Correct |
145 ms |
7544 KB |
Output is correct |
51 |
Correct |
124 ms |
8660 KB |
Output is correct |
52 |
Correct |
147 ms |
8592 KB |
Output is correct |
53 |
Correct |
227 ms |
8588 KB |
Output is correct |
54 |
Correct |
136 ms |
9728 KB |
Output is correct |
55 |
Correct |
118 ms |
9760 KB |
Output is correct |
56 |
Correct |
215 ms |
9724 KB |
Output is correct |
57 |
Correct |
170 ms |
10916 KB |
Output is correct |
58 |
Correct |
139 ms |
10952 KB |
Output is correct |
59 |
Correct |
259 ms |
10928 KB |
Output is correct |
60 |
Correct |
181 ms |
12248 KB |
Output is correct |
61 |
Correct |
164 ms |
12256 KB |
Output is correct |
62 |
Correct |
295 ms |
12224 KB |
Output is correct |
63 |
Correct |
402 ms |
12220 KB |
Output is correct |
64 |
Correct |
487 ms |
12232 KB |
Output is correct |
65 |
Correct |
438 ms |
12248 KB |
Output is correct |
66 |
Correct |
391 ms |
12236 KB |
Output is correct |
67 |
Correct |
406 ms |
12244 KB |
Output is correct |
68 |
Correct |
344 ms |
12244 KB |
Output is correct |
69 |
Correct |
368 ms |
12232 KB |
Output is correct |
70 |
Correct |
362 ms |
12248 KB |
Output is correct |
71 |
Correct |
381 ms |
12252 KB |
Output is correct |
72 |
Incorrect |
335 ms |
12256 KB |
Output isn't correct |
73 |
Incorrect |
309 ms |
12304 KB |
Output isn't correct |
74 |
Correct |
348 ms |
12296 KB |
Output is correct |
75 |
Correct |
341 ms |
12268 KB |
Output is correct |
76 |
Correct |
354 ms |
12296 KB |
Output is correct |
77 |
Correct |
372 ms |
12312 KB |
Output is correct |
78 |
Correct |
319 ms |
12288 KB |
Output is correct |
79 |
Correct |
304 ms |
12272 KB |
Output is correct |
80 |
Correct |
334 ms |
12368 KB |
Output is correct |
81 |
Correct |
318 ms |
12292 KB |
Output is correct |
82 |
Correct |
337 ms |
12360 KB |
Output is correct |
83 |
Correct |
339 ms |
12300 KB |
Output is correct |
84 |
Correct |
349 ms |
12284 KB |
Output is correct |
85 |
Correct |
340 ms |
12272 KB |
Output is correct |
86 |
Correct |
323 ms |
12248 KB |
Output is correct |
87 |
Correct |
338 ms |
12300 KB |
Output is correct |
88 |
Correct |
328 ms |
12252 KB |
Output is correct |
89 |
Correct |
327 ms |
12288 KB |
Output is correct |
90 |
Correct |
356 ms |
12300 KB |
Output is correct |
91 |
Correct |
377 ms |
12276 KB |
Output is correct |
92 |
Correct |
360 ms |
12292 KB |
Output is correct |