# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135481 | 2019-07-24T06:33:13 Z | Dilshod_Imomov | Mecho (IOI09_mecho) | C++17 | 1000 ms | 17596 KB |
# include <bits/stdc++.h> # define ll long long # define fi first # define se second # define pb push_back # define pf push_front # define For(i, a, b) for( int i = a; i < b; i++ ) # define in insert # define all(a) a.begin(),a.end() # define pi pair < int, int > # define DEBUG # define readfile(file) freopen ( (file + ".in").c_str(), "r", stdin) # define writefile(file) freopen ( (file + ".out").c_str(), "w", stdout) # define speed ios_base::sync_with_stdio(false);cin.tie(NULL) # define LARGE (1e7) using namespace std; void Set_File( string file ){readfile(file);writefile(file);} int n, s; string m; vector < string > forest; vector < string > forest1; int step[1000][1000]; int visited[1000][1000]; int x, ans = -1; pi pos = { -1, -1 }; vector < pi > add = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }; int valid ( int i, int j ){ if ( i >= 0 && i < n && j >= 0 && j < n && forest[i][j] != 'T' ) { return 1; } return 0; } void spread_bees(){ vector < pi > pos; For ( i, 0, n ){ For ( j, 0, n ){ if ( forest[i][j] == 'H' ) { pos.pb({i, j}); } } } For ( i, 0, pos.size() ){ For ( j, 0, 4 ){ pi neighbour = { pos[i].fi + add[j].fi, pos[i].se + add[j].se }; if ( valid( neighbour.fi, neighbour.se ) && forest[neighbour.fi][neighbour.se] == 'G' && forest[neighbour.fi][neighbour.se] != 'D' ){ forest[neighbour.fi][neighbour.se] = 'H'; } } } } int main(){ /// Author: _Dilshod_ speed; cin >> n >> s; For ( i, 0, n ){ cin >> m; forest.pb(m); forest1.pb(m); if ( pos.fi == -1 ){ For ( j, 0, m.size() ){ if ( m[j] == 'M' ){ pos = {i, j}; } } } } while ( 1 ){ int ans1 = -1; queue < pi > BFS; BFS.push(pos); forest = forest1; For ( i, 0, 1000 ){ For ( j, 0, 1000 ){ step[i][j] = 0; visited[i][j] = 0; } } For ( i, 0, x ){ spread_bees(); } int y = x; int z = 0; pi loc = pos; visited[loc.fi][loc.se] = 1; while ( !BFS.empty() ){ loc = BFS.front(); if ( step[loc.fi][loc.se] == 0 ){ spread_bees(); y++; } if ( step[loc.fi][loc.se] == 1 && z ){ z = 0; spread_bees(); y++; } if ( forest[loc.fi][loc.se] == 'D' ){ ans1 = max( ans1, x ); break; } BFS.pop(); if ( step[loc.fi][loc.se] == s ){ if ( forest[loc.fi][loc.se] == 'H' ) { continue; } step[loc.fi][loc.se] = 0; } For ( i, 0, 4 ){ pi to = { loc.fi + add[i].fi, loc.se + add[i].se }; if ( valid( to.fi, to.se ) && !visited[to.fi][to.se] ) { visited[to.fi][to.se] = 1; if ( step[loc.fi][loc.se] == 2 ) { z++; } step[to.fi][to.se] = step[loc.fi][loc.se] + 1; BFS.push(to); } } if ( BFS.empty() && forest[loc.fi][loc.se] != 'D' ) { ans1 = -1; break; } } x++; ans = max( ans1, ans ); if ( ans1 == -1 ){ break; } } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 8184 KB | Output is correct |
2 | Incorrect | 15 ms | 8184 KB | Output isn't correct |
3 | Correct | 14 ms | 8184 KB | Output is correct |
4 | Incorrect | 15 ms | 8184 KB | Output isn't correct |
5 | Incorrect | 13 ms | 8184 KB | Output isn't correct |
6 | Incorrect | 15 ms | 8184 KB | Output isn't correct |
7 | Execution timed out | 1055 ms | 16664 KB | Time limit exceeded |
8 | Incorrect | 16 ms | 8184 KB | Output isn't correct |
9 | Correct | 24 ms | 8184 KB | Output is correct |
10 | Incorrect | 21 ms | 8184 KB | Output isn't correct |
11 | Incorrect | 22 ms | 8312 KB | Output isn't correct |
12 | Execution timed out | 1073 ms | 8440 KB | Time limit exceeded |
13 | Incorrect | 19 ms | 8184 KB | Output isn't correct |
14 | Correct | 11 ms | 8312 KB | Output is correct |
15 | Correct | 299 ms | 8224 KB | Output is correct |
16 | Incorrect | 141 ms | 8184 KB | Output isn't correct |
17 | Correct | 592 ms | 8316 KB | Output is correct |
18 | Incorrect | 253 ms | 8184 KB | Output isn't correct |
19 | Execution timed out | 1062 ms | 8440 KB | Time limit exceeded |
20 | Incorrect | 398 ms | 8212 KB | Output isn't correct |
21 | Execution timed out | 1069 ms | 8348 KB | Time limit exceeded |
22 | Execution timed out | 1070 ms | 8440 KB | Time limit exceeded |
23 | Execution timed out | 1069 ms | 8184 KB | Time limit exceeded |
24 | Execution timed out | 1071 ms | 8292 KB | Time limit exceeded |
25 | Execution timed out | 1074 ms | 8236 KB | Time limit exceeded |
26 | Execution timed out | 1077 ms | 8184 KB | Time limit exceeded |
27 | Execution timed out | 1073 ms | 8240 KB | Time limit exceeded |
28 | Execution timed out | 1086 ms | 8184 KB | Time limit exceeded |
29 | Execution timed out | 1055 ms | 8240 KB | Time limit exceeded |
30 | Execution timed out | 1078 ms | 8184 KB | Time limit exceeded |
31 | Execution timed out | 1069 ms | 8316 KB | Time limit exceeded |
32 | Execution timed out | 1061 ms | 8316 KB | Time limit exceeded |
33 | Execution timed out | 1075 ms | 8568 KB | Time limit exceeded |
34 | Execution timed out | 1068 ms | 8648 KB | Time limit exceeded |
35 | Execution timed out | 1075 ms | 8824 KB | Time limit exceeded |
36 | Execution timed out | 1072 ms | 8724 KB | Time limit exceeded |
37 | Execution timed out | 1077 ms | 8696 KB | Time limit exceeded |
38 | Execution timed out | 1065 ms | 9004 KB | Time limit exceeded |
39 | Execution timed out | 1080 ms | 8824 KB | Time limit exceeded |
40 | Execution timed out | 1086 ms | 8952 KB | Time limit exceeded |
41 | Execution timed out | 1070 ms | 8952 KB | Time limit exceeded |
42 | Execution timed out | 1074 ms | 8952 KB | Time limit exceeded |
43 | Execution timed out | 1037 ms | 8952 KB | Time limit exceeded |
44 | Execution timed out | 1046 ms | 9032 KB | Time limit exceeded |
45 | Execution timed out | 1087 ms | 9080 KB | Time limit exceeded |
46 | Execution timed out | 1082 ms | 9080 KB | Time limit exceeded |
47 | Execution timed out | 1092 ms | 9204 KB | Time limit exceeded |
48 | Execution timed out | 1069 ms | 9336 KB | Time limit exceeded |
49 | Execution timed out | 1077 ms | 9336 KB | Time limit exceeded |
50 | Execution timed out | 1068 ms | 9592 KB | Time limit exceeded |
51 | Execution timed out | 1075 ms | 9464 KB | Time limit exceeded |
52 | Execution timed out | 1078 ms | 9464 KB | Time limit exceeded |
53 | Execution timed out | 1075 ms | 9668 KB | Time limit exceeded |
54 | Execution timed out | 1078 ms | 9720 KB | Time limit exceeded |
55 | Execution timed out | 1079 ms | 9720 KB | Time limit exceeded |
56 | Execution timed out | 1076 ms | 9976 KB | Time limit exceeded |
57 | Execution timed out | 1086 ms | 9976 KB | Time limit exceeded |
58 | Execution timed out | 1074 ms | 9976 KB | Time limit exceeded |
59 | Execution timed out | 1074 ms | 10104 KB | Time limit exceeded |
60 | Execution timed out | 1083 ms | 10104 KB | Time limit exceeded |
61 | Execution timed out | 1077 ms | 10108 KB | Time limit exceeded |
62 | Execution timed out | 1080 ms | 10184 KB | Time limit exceeded |
63 | Execution timed out | 1062 ms | 10232 KB | Time limit exceeded |
64 | Execution timed out | 1081 ms | 10336 KB | Time limit exceeded |
65 | Execution timed out | 1073 ms | 10824 KB | Time limit exceeded |
66 | Execution timed out | 1054 ms | 11228 KB | Time limit exceeded |
67 | Execution timed out | 1066 ms | 10236 KB | Time limit exceeded |
68 | Execution timed out | 1084 ms | 13992 KB | Time limit exceeded |
69 | Execution timed out | 1068 ms | 11816 KB | Time limit exceeded |
70 | Execution timed out | 1079 ms | 16580 KB | Time limit exceeded |
71 | Execution timed out | 1079 ms | 16428 KB | Time limit exceeded |
72 | Execution timed out | 1061 ms | 12040 KB | Time limit exceeded |
73 | Execution timed out | 1069 ms | 17464 KB | Time limit exceeded |
74 | Execution timed out | 1068 ms | 16860 KB | Time limit exceeded |
75 | Execution timed out | 1077 ms | 17448 KB | Time limit exceeded |
76 | Execution timed out | 1076 ms | 17324 KB | Time limit exceeded |
77 | Execution timed out | 1078 ms | 17132 KB | Time limit exceeded |
78 | Execution timed out | 1073 ms | 17324 KB | Time limit exceeded |
79 | Execution timed out | 1069 ms | 16604 KB | Time limit exceeded |
80 | Execution timed out | 1069 ms | 17596 KB | Time limit exceeded |
81 | Execution timed out | 1073 ms | 17392 KB | Time limit exceeded |
82 | Execution timed out | 1068 ms | 16988 KB | Time limit exceeded |
83 | Execution timed out | 1078 ms | 17244 KB | Time limit exceeded |
84 | Execution timed out | 1075 ms | 16516 KB | Time limit exceeded |
85 | Execution timed out | 1079 ms | 17140 KB | Time limit exceeded |
86 | Execution timed out | 1069 ms | 17396 KB | Time limit exceeded |
87 | Execution timed out | 1074 ms | 17164 KB | Time limit exceeded |
88 | Execution timed out | 1084 ms | 17164 KB | Time limit exceeded |
89 | Execution timed out | 1076 ms | 14340 KB | Time limit exceeded |
90 | Execution timed out | 1083 ms | 17036 KB | Time limit exceeded |
91 | Execution timed out | 1062 ms | 16704 KB | Time limit exceeded |
92 | Execution timed out | 1041 ms | 17244 KB | Time limit exceeded |