# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
624582 |
2022-08-08T13:52:05 Z |
jackkkk |
Mecho (IOI09_mecho) |
C++11 |
|
434 ms |
3540 KB |
// Mecho
// https://oj.uz/problem/view/IOI09_mecho
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <array>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <float.h>
#include <climits>
#include <cmath>
using namespace std;
void quit() {
cout.flush();
exit(0);
}
int n, s;
pair<int, int> st, dest;
bool tree[800][800]; //contains trees and grass. bee hives are also trees
bool tmp[800][800];
bool mecho_done[800][800];
deque<pair<int, int>> hives, mecho, tmp1, tmp2, new_hives, new_mecho;
pair<int, int> gto[4] = {{0,1}, {0,-1}, {-1,0}, {1,0}};
bool in_grid(int a, int b){
return a >= 0 && a < n && b >= 0 && b < n;
}
bool bee_can_go(int a, int b){
return in_grid(a,b) && !(a == dest.first && b == dest.second) && !tree[a][b];
}
bool mecho_can_go(int a, int b){
return in_grid(a,b) && !mecho_done[a][b] && !tree[a][b];
}
void bee_expand(){
new_hives.clear();
while(!hives.empty()){
pair<int, int> curr = hives.front();
int cx = curr.first, cy = curr.second;
hives.pop_front();
for(const auto &to : gto){
int nx = to.first +cx, ny = to.second+cy;
if(bee_can_go(nx, ny)){
new_hives.emplace_back(nx, ny);
tree[nx][ny]=1;
}
}
}
hives=new_hives;
}
bool finished;
bool mecho_expand(){
//if can't expand anymore return false
for(int i = 0; i < s; i++){
new_mecho.clear();
while(!mecho.empty()){
pair<int, int> curr = mecho.front();
int cx = curr.first, cy = curr.second;
mecho.pop_front();
for(const auto &to : gto){
int nx = to.first +cx, ny = to.second+cy;
if(mecho_can_go(nx, ny)){
new_mecho.emplace_back(nx, ny);
mecho_done[nx][ny]=1;
}
if(nx == dest.first && ny == dest.second){
//can get to dest
finished=true;
return false;
}
}
}
mecho=new_mecho;
}
return mecho.size()>0;
}
bool good(int wait_time){
tmp1 = hives;
tmp2 = mecho;
for(int i = 0; i < 800; i++){
for(int j = 0; j < 800; j++){
mecho_done[i][j]=0;
tmp[i][j]=tree[i][j];
}
}
mecho_done[st.first][st.second]=1;
finished=false;
//propogate until can't
for(int i = 0; i < wait_time; i++){
bee_expand();
}
while(mecho_expand()){
bee_expand();
/*
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cerr <<tree[i][j] << " ";
}
cerr << "\n";
}
*/
}
//reset variables
for(int i = 0; i < 800; i++){
for(int j = 0; j < 800; j++){
tree[i][j]=tmp[i][j];
}
}
hives=tmp1;
mecho=tmp2;
return finished;
}
int main(void){
//freopen("qwer.in", "r", stdin);
//freopen("qwer.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s;
for(int i = 0; i < n; i++){
string s; cin >> s;
for(int j = 0; j < n; j++){
if(s[j]=='T'){
tree[i][j]=1;
}
else if(s[j]=='M'){
st={i,j};
mecho.emplace_back(i,j);
}
else if(s[j]=='D'){
dest = {i,j};
}
else if(s[j] == 'H'){
hives.emplace_back(i,j);
tree[i][j]=1;
}
}
}
if(!good(0)){
cout << "-1\n";
quit();
}
int s = 0, e = 1e6;
while(s != e){
int md = (s+e+1)/2;
if(good(md)){
s=md;
}
else{
e=md-1;
}
}
cout << s << "\n";
quit();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
2252 KB |
Output isn't correct |
2 |
Incorrect |
26 ms |
2132 KB |
Output isn't correct |
3 |
Incorrect |
34 ms |
2132 KB |
Output isn't correct |
4 |
Incorrect |
26 ms |
2132 KB |
Output isn't correct |
5 |
Correct |
35 ms |
2200 KB |
Output is correct |
6 |
Correct |
38 ms |
2180 KB |
Output is correct |
7 |
Correct |
321 ms |
3068 KB |
Output is correct |
8 |
Incorrect |
25 ms |
2132 KB |
Output isn't correct |
9 |
Correct |
32 ms |
2196 KB |
Output is correct |
10 |
Correct |
26 ms |
2132 KB |
Output is correct |
11 |
Correct |
27 ms |
2132 KB |
Output is correct |
12 |
Incorrect |
434 ms |
2196 KB |
Output isn't correct |
13 |
Incorrect |
28 ms |
2132 KB |
Output isn't correct |
14 |
Correct |
1 ms |
2132 KB |
Output is correct |
15 |
Incorrect |
25 ms |
2184 KB |
Output isn't correct |
16 |
Correct |
26 ms |
2192 KB |
Output is correct |
17 |
Incorrect |
26 ms |
2124 KB |
Output isn't correct |
18 |
Correct |
26 ms |
2132 KB |
Output is correct |
19 |
Incorrect |
25 ms |
2132 KB |
Output isn't correct |
20 |
Correct |
26 ms |
2132 KB |
Output is correct |
21 |
Incorrect |
26 ms |
2208 KB |
Output isn't correct |
22 |
Correct |
27 ms |
2132 KB |
Output is correct |
23 |
Incorrect |
26 ms |
2132 KB |
Output isn't correct |
24 |
Correct |
27 ms |
2132 KB |
Output is correct |
25 |
Incorrect |
28 ms |
2124 KB |
Output isn't correct |
26 |
Correct |
28 ms |
2184 KB |
Output is correct |
27 |
Incorrect |
27 ms |
2132 KB |
Output isn't correct |
28 |
Correct |
32 ms |
2212 KB |
Output is correct |
29 |
Incorrect |
35 ms |
2200 KB |
Output isn't correct |
30 |
Correct |
28 ms |
2208 KB |
Output is correct |
31 |
Incorrect |
27 ms |
2204 KB |
Output isn't correct |
32 |
Correct |
28 ms |
2208 KB |
Output is correct |
33 |
Incorrect |
67 ms |
2388 KB |
Output isn't correct |
34 |
Correct |
72 ms |
2304 KB |
Output is correct |
35 |
Correct |
69 ms |
2260 KB |
Output is correct |
36 |
Incorrect |
93 ms |
2348 KB |
Output isn't correct |
37 |
Correct |
86 ms |
2348 KB |
Output is correct |
38 |
Correct |
76 ms |
2260 KB |
Output is correct |
39 |
Incorrect |
147 ms |
2412 KB |
Output isn't correct |
40 |
Correct |
103 ms |
2400 KB |
Output is correct |
41 |
Correct |
90 ms |
2408 KB |
Output is correct |
42 |
Incorrect |
114 ms |
2452 KB |
Output isn't correct |
43 |
Correct |
114 ms |
2388 KB |
Output is correct |
44 |
Correct |
110 ms |
2376 KB |
Output is correct |
45 |
Incorrect |
144 ms |
2500 KB |
Output isn't correct |
46 |
Correct |
143 ms |
2516 KB |
Output is correct |
47 |
Correct |
119 ms |
2516 KB |
Output is correct |
48 |
Incorrect |
183 ms |
2560 KB |
Output isn't correct |
49 |
Correct |
174 ms |
2504 KB |
Output is correct |
50 |
Correct |
139 ms |
2580 KB |
Output is correct |
51 |
Incorrect |
187 ms |
2644 KB |
Output isn't correct |
52 |
Correct |
186 ms |
2644 KB |
Output is correct |
53 |
Correct |
156 ms |
2648 KB |
Output is correct |
54 |
Incorrect |
240 ms |
2688 KB |
Output isn't correct |
55 |
Correct |
196 ms |
2684 KB |
Output is correct |
56 |
Correct |
175 ms |
2708 KB |
Output is correct |
57 |
Incorrect |
274 ms |
2772 KB |
Output isn't correct |
58 |
Correct |
228 ms |
2772 KB |
Output is correct |
59 |
Correct |
206 ms |
2784 KB |
Output is correct |
60 |
Incorrect |
260 ms |
2844 KB |
Output isn't correct |
61 |
Correct |
281 ms |
2844 KB |
Output is correct |
62 |
Correct |
219 ms |
2856 KB |
Output is correct |
63 |
Correct |
293 ms |
2856 KB |
Output is correct |
64 |
Correct |
302 ms |
2864 KB |
Output is correct |
65 |
Correct |
324 ms |
2852 KB |
Output is correct |
66 |
Incorrect |
330 ms |
2892 KB |
Output isn't correct |
67 |
Correct |
21 ms |
2772 KB |
Output is correct |
68 |
Correct |
277 ms |
2900 KB |
Output is correct |
69 |
Correct |
258 ms |
2904 KB |
Output is correct |
70 |
Correct |
289 ms |
2904 KB |
Output is correct |
71 |
Correct |
256 ms |
2916 KB |
Output is correct |
72 |
Incorrect |
293 ms |
2904 KB |
Output isn't correct |
73 |
Incorrect |
302 ms |
3540 KB |
Output isn't correct |
74 |
Correct |
345 ms |
3412 KB |
Output is correct |
75 |
Correct |
353 ms |
3412 KB |
Output is correct |
76 |
Correct |
395 ms |
3492 KB |
Output is correct |
77 |
Correct |
356 ms |
3508 KB |
Output is correct |
78 |
Correct |
20 ms |
3356 KB |
Output is correct |
79 |
Correct |
330 ms |
3396 KB |
Output is correct |
80 |
Correct |
351 ms |
3504 KB |
Output is correct |
81 |
Correct |
344 ms |
3340 KB |
Output is correct |
82 |
Correct |
333 ms |
3360 KB |
Output is correct |
83 |
Correct |
336 ms |
3276 KB |
Output is correct |
84 |
Correct |
317 ms |
3304 KB |
Output is correct |
85 |
Correct |
341 ms |
3264 KB |
Output is correct |
86 |
Correct |
328 ms |
3300 KB |
Output is correct |
87 |
Correct |
332 ms |
3284 KB |
Output is correct |
88 |
Correct |
315 ms |
3168 KB |
Output is correct |
89 |
Correct |
318 ms |
3420 KB |
Output is correct |
90 |
Correct |
326 ms |
3160 KB |
Output is correct |
91 |
Correct |
343 ms |
3308 KB |
Output is correct |
92 |
Correct |
326 ms |
3132 KB |
Output is correct |