# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1083669 |
2024-09-03T19:02:19 Z |
hohemhein |
Mecho (IOI09_mecho) |
C++17 |
|
109 ms |
13424 KB |
#include <bits/stdc++.h>
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define f first
#define s second
#define pb push_back
#define pu push
#define ll long long
#define int long long
#define endl "\n"
#define all(x) (x).begin() , (x).end()
using namespace std;
const int nmax = 8e2+4;
const int oo = 1e12+3;
const ll mod = 1e9+7;
char m[nmax][nmax];
int bee[nmax][nmax];
int bear[nmax][nmax];
int mov[] = { 1,-1 };
void llenar(){
for( int i = 0; i < nmax; i++ ){
fill( bear[i], bear[i]+nmax, -1 );
fill( bee[i], bee[i]+nmax, oo );
}
}
void bfsBee( vector<ii>&aux, int n ){
queue<ii>c;
for( auto [i,j] : aux ){
c.pu({i,j});
bee[i][j] = 0;
}
while( !c.empty() ){
auto [x,y] = c.front();
c.pop();
for( int i = 0; i < 2; i++ )
if( x+mov[i] > 0 && x+mov[i] <= n && m[ x+mov[i] ][y] == 'G' && bee[ x+mov[i] ][y] == oo ){
c.pu( {x+mov[i],y} );
bee[ x+mov[i] ][y] = bee[x][y]+1;
}
for( int i = 0; i < 2; i++ )
if( y+mov[i] > 0 && y+mov[i] <= n && m[x][y+mov[i]] == 'G' && bee[x][y+mov[i]] == oo ){
c.pu( {x,y+mov[i]} );
bee[x][y+mov[i]] = bee[x][y]+1;
}
}
}
void bfsBear( ii X, int n, int k ){
priority_queue<iiii>c;
bear[X.f][X.s] = bee[X.f][X.s] - 1;
c.pu({ {bear[X.f][X.s],0} , X });
while( !c.empty() ){
auto [x,y] = c.top().s;
auto [val,pe] = c.top().f;
pe*=-1;
c.pop();
if( bear[x][y] != val )continue;
for( int i = 0; i < 2; i++ ){
int newValue = min( val , bee[x+mov[i]][y] - pe/k - 1 );
if( x+mov[i] > 0 && x+mov[i] <= n && m[ x+mov[i] ][y] != 'T' && bear[ x+mov[i] ][y] < newValue && bee[ x+mov[i] ][y] > pe/k ){
c.pu( { { newValue, -(pe+1) }, {x+mov[i],y} } );
bear[ x+mov[i] ][y] = newValue;
}
}
for( int i = 0; i < 2; i++ ){
int newValue = min( bear[x][y] , bee[x][y+mov[i]] - pe/k -1 );
if( y+mov[i] > 0 && y+mov[i] <= n && m[x][y+mov[i]] != 'T'&& bear[x][y+mov[i]] < newValue && bee[x][y+mov[i]] > pe/k ){
c.pu( { {newValue,-(pe+1)}, {x,y+mov[i]} } );
bear[x][y+mov[i]] = newValue;
}
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie();
//cout << fixed << setprecision(4);
/*ifstream cin ("atlarge.in");
ofstream cout ("atlarge.out");*/
llenar();
int n, k; cin >> n >> k;
ii init, meta;
vector<ii>aux;
for( int i = 1; i <= n; i++ )
for( int j = 1; j <= n; j++ ){
cin >> m[i][j];
if( m[i][j] == 'H' )aux.pb({i,j});
else if( m[i][j] == 'M' )init = {i,j};
else if( m[i][j] == 'D' )meta = {i,j};
}
m[init.f][init.s] = 'G';
bfsBee( aux, n );
bfsBear( init, n, k);
/* for( int i = 1; i <= n; i++ ){
for( int j = 1; j <= n; j++ )
cout << bear[i][j] <<" ";
cout <<"\n";
}*/
cout << bear[meta.f][meta.s] <<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
10584 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
10332 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
10588 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
10588 KB |
Output isn't correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
4 ms |
10588 KB |
Output is correct |
7 |
Correct |
59 ms |
12080 KB |
Output is correct |
8 |
Incorrect |
4 ms |
10584 KB |
Output isn't correct |
9 |
Correct |
4 ms |
10588 KB |
Output is correct |
10 |
Correct |
4 ms |
10588 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
5 ms |
10580 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10588 KB |
Output is correct |
15 |
Incorrect |
4 ms |
10588 KB |
Output isn't correct |
16 |
Correct |
4 ms |
10588 KB |
Output is correct |
17 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
18 |
Correct |
6 ms |
10840 KB |
Output is correct |
19 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
20 |
Correct |
5 ms |
10588 KB |
Output is correct |
21 |
Incorrect |
4 ms |
10588 KB |
Output isn't correct |
22 |
Correct |
4 ms |
10544 KB |
Output is correct |
23 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
24 |
Correct |
4 ms |
10464 KB |
Output is correct |
25 |
Incorrect |
4 ms |
10552 KB |
Output isn't correct |
26 |
Correct |
4 ms |
10588 KB |
Output is correct |
27 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
28 |
Correct |
4 ms |
10588 KB |
Output is correct |
29 |
Incorrect |
5 ms |
10584 KB |
Output isn't correct |
30 |
Correct |
4 ms |
10588 KB |
Output is correct |
31 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
32 |
Correct |
4 ms |
10588 KB |
Output is correct |
33 |
Incorrect |
7 ms |
10844 KB |
Output isn't correct |
34 |
Correct |
8 ms |
10844 KB |
Output is correct |
35 |
Correct |
14 ms |
11096 KB |
Output is correct |
36 |
Incorrect |
9 ms |
10844 KB |
Output isn't correct |
37 |
Correct |
8 ms |
10852 KB |
Output is correct |
38 |
Correct |
17 ms |
11100 KB |
Output is correct |
39 |
Incorrect |
8 ms |
10992 KB |
Output isn't correct |
40 |
Correct |
9 ms |
11100 KB |
Output is correct |
41 |
Correct |
20 ms |
11196 KB |
Output is correct |
42 |
Incorrect |
10 ms |
10972 KB |
Output isn't correct |
43 |
Correct |
10 ms |
11100 KB |
Output is correct |
44 |
Correct |
25 ms |
11284 KB |
Output is correct |
45 |
Incorrect |
14 ms |
11100 KB |
Output isn't correct |
46 |
Correct |
13 ms |
11100 KB |
Output is correct |
47 |
Correct |
30 ms |
11356 KB |
Output is correct |
48 |
Incorrect |
12 ms |
11356 KB |
Output isn't correct |
49 |
Correct |
14 ms |
11404 KB |
Output is correct |
50 |
Correct |
36 ms |
11356 KB |
Output is correct |
51 |
Incorrect |
14 ms |
11356 KB |
Output isn't correct |
52 |
Correct |
19 ms |
11356 KB |
Output is correct |
53 |
Correct |
46 ms |
11356 KB |
Output is correct |
54 |
Incorrect |
17 ms |
11612 KB |
Output isn't correct |
55 |
Correct |
16 ms |
11608 KB |
Output is correct |
56 |
Correct |
46 ms |
11612 KB |
Output is correct |
57 |
Incorrect |
17 ms |
11612 KB |
Output isn't correct |
58 |
Correct |
18 ms |
11720 KB |
Output is correct |
59 |
Correct |
53 ms |
11732 KB |
Output is correct |
60 |
Incorrect |
17 ms |
11612 KB |
Output isn't correct |
61 |
Correct |
20 ms |
11836 KB |
Output is correct |
62 |
Correct |
64 ms |
11896 KB |
Output is correct |
63 |
Correct |
49 ms |
11864 KB |
Output is correct |
64 |
Correct |
60 ms |
11836 KB |
Output is correct |
65 |
Correct |
52 ms |
11612 KB |
Output is correct |
66 |
Incorrect |
47 ms |
11856 KB |
Output isn't correct |
67 |
Correct |
40 ms |
11844 KB |
Output is correct |
68 |
Correct |
32 ms |
11868 KB |
Output is correct |
69 |
Correct |
35 ms |
11884 KB |
Output is correct |
70 |
Correct |
29 ms |
11868 KB |
Output is correct |
71 |
Correct |
32 ms |
11888 KB |
Output is correct |
72 |
Correct |
37 ms |
11868 KB |
Output is correct |
73 |
Correct |
46 ms |
12420 KB |
Output is correct |
74 |
Incorrect |
108 ms |
13424 KB |
Output isn't correct |
75 |
Incorrect |
51 ms |
12376 KB |
Output isn't correct |
76 |
Incorrect |
48 ms |
12428 KB |
Output isn't correct |
77 |
Correct |
52 ms |
12380 KB |
Output is correct |
78 |
Correct |
56 ms |
12380 KB |
Output is correct |
79 |
Incorrect |
109 ms |
13384 KB |
Output isn't correct |
80 |
Correct |
52 ms |
12380 KB |
Output is correct |
81 |
Incorrect |
50 ms |
12380 KB |
Output isn't correct |
82 |
Incorrect |
55 ms |
12120 KB |
Output isn't correct |
83 |
Incorrect |
56 ms |
12120 KB |
Output isn't correct |
84 |
Incorrect |
107 ms |
13132 KB |
Output isn't correct |
85 |
Correct |
56 ms |
12124 KB |
Output is correct |
86 |
Incorrect |
53 ms |
12268 KB |
Output isn't correct |
87 |
Correct |
66 ms |
12120 KB |
Output is correct |
88 |
Incorrect |
58 ms |
11936 KB |
Output isn't correct |
89 |
Incorrect |
109 ms |
13132 KB |
Output isn't correct |
90 |
Correct |
60 ms |
12120 KB |
Output is correct |
91 |
Correct |
72 ms |
12628 KB |
Output is correct |
92 |
Correct |
53 ms |
12124 KB |
Output is correct |