# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988359 |
2024-05-24T14:34:38 Z |
steveonalex |
Mecho (IOI09_mecho) |
C++17 |
|
215 ms |
8016 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int N = 900;
const int INF = 1e6 + 69;
int n, s;
bitset<N> grid[N];
int dis1[N][N], dis2[N][N];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s;
vector<string> field(n);
for(int i = 0; i<n; ++i) cin >> field[i];
for(int i = 0; i<=n+1; ++i) grid[i][0] = grid[0][i] = grid[i][n+1] = grid[n+1][i] = 1;
for(int i = 0; i<n; ++i) for(int j = 0 ;j<n; ++j) if (field[i][j] == 'T' || field[i][j] == 'D'){
grid[i+1][j+1] = 1;
}
for(int i = 0; i<=n+1; ++i) for(int j = 0; j<=n+1; ++j) dis1[i][j] = INF;
deque<pair<int, int>> q;
for(int i = 0; i<n; ++i) for(int j = 0; j<n; ++j) if (field[i][j] == 'H') {
q.push_back({i + 1, j+1});
dis1[i+1][j+1] = 0;
}
while(q.size()){
pair<int, int> u = q.front(); q.pop_front();
for(int dir = 0; dir < 4; ++dir){
pair<int, int> v = {u.first + dx[dir], u.second + dy[dir]};
if (!grid[v.first][v.second] && minimize(dis1[v.first][v.second], dis1[u.first][u.second] + 1)){
q.push_back(v);
}
}
}
pair<int, int> S, E;
for(int i = 0; i<n; ++i) for(int j = 0; j<n; ++j){
if (field[i][j] == 'D') E = {i+1, j+1};
if (field[i][j] == 'M') S = {i+1, j+1};
}
grid[E.first][E.second] = 0;
ll l = -1, r = 2 * n * n;
minimize(r, dis1[S.first][S.second] * s - 1);
while(l < r){
ll mid = (l + r + 1) >> 1;
for(int i = 0; i<=n+1; ++i) for(int j = 0; j<=n+1; ++j) dis2[i][j] = INF;
dis2[S.first][S.second] = mid;
deque<pair<int, int>> q; q.push_back(S);
while(q.size()){
pair<int, int> u = q.front(); q.pop_front();
int cur = dis2[u.first][u.second];
for(int dir = 0; dir < 4; ++dir){
pair<int, int> v = {u.first + dx[dir], u.second + dy[dir]};
if (!grid[v.first][v.second] && dis1[v.first][v.second] > (cur + 1) / s && minimize(dis2[v.first][v.second], cur + 1)){
q.push_back(v);
}
}
}
if (dis2[E.first][E.second] == INF) r = mid - 1;
else l = mid;
}
if (l == n * n * 2) exit(1);
if (l >= 0) l /= s;
cout << l << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
105 ms |
7672 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4588 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Runtime error |
1 ms |
2396 KB |
Execution failed because the return code was nonzero |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Runtime error |
1 ms |
2396 KB |
Execution failed because the return code was nonzero |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Runtime error |
1 ms |
2396 KB |
Execution failed because the return code was nonzero |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Runtime error |
1 ms |
2648 KB |
Execution failed because the return code was nonzero |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Runtime error |
2 ms |
4696 KB |
Execution failed because the return code was nonzero |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Runtime error |
2 ms |
4700 KB |
Execution failed because the return code was nonzero |
27 |
Correct |
2 ms |
4700 KB |
Output is correct |
28 |
Runtime error |
2 ms |
4696 KB |
Execution failed because the return code was nonzero |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Runtime error |
2 ms |
4700 KB |
Execution failed because the return code was nonzero |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Runtime error |
2 ms |
4700 KB |
Execution failed because the return code was nonzero |
33 |
Correct |
5 ms |
7000 KB |
Output is correct |
34 |
Runtime error |
21 ms |
6748 KB |
Execution failed because the return code was nonzero |
35 |
Correct |
33 ms |
6748 KB |
Output is correct |
36 |
Correct |
6 ms |
7000 KB |
Output is correct |
37 |
Runtime error |
26 ms |
7004 KB |
Execution failed because the return code was nonzero |
38 |
Correct |
40 ms |
7004 KB |
Output is correct |
39 |
Correct |
7 ms |
7004 KB |
Output is correct |
40 |
Runtime error |
33 ms |
6908 KB |
Execution failed because the return code was nonzero |
41 |
Correct |
52 ms |
7056 KB |
Output is correct |
42 |
Correct |
7 ms |
7004 KB |
Output is correct |
43 |
Runtime error |
43 ms |
7004 KB |
Execution failed because the return code was nonzero |
44 |
Correct |
64 ms |
7004 KB |
Output is correct |
45 |
Correct |
9 ms |
7004 KB |
Output is correct |
46 |
Runtime error |
49 ms |
7000 KB |
Execution failed because the return code was nonzero |
47 |
Correct |
76 ms |
7004 KB |
Output is correct |
48 |
Correct |
10 ms |
7256 KB |
Output is correct |
49 |
Runtime error |
58 ms |
7260 KB |
Execution failed because the return code was nonzero |
50 |
Correct |
91 ms |
7256 KB |
Output is correct |
51 |
Correct |
12 ms |
7256 KB |
Output is correct |
52 |
Runtime error |
70 ms |
7260 KB |
Execution failed because the return code was nonzero |
53 |
Correct |
121 ms |
7512 KB |
Output is correct |
54 |
Correct |
13 ms |
7260 KB |
Output is correct |
55 |
Runtime error |
35 ms |
7260 KB |
Execution failed because the return code was nonzero |
56 |
Correct |
130 ms |
7260 KB |
Output is correct |
57 |
Correct |
14 ms |
7260 KB |
Output is correct |
58 |
Incorrect |
21 ms |
7260 KB |
Output isn't correct |
59 |
Correct |
151 ms |
7260 KB |
Output is correct |
60 |
Correct |
16 ms |
7512 KB |
Output is correct |
61 |
Incorrect |
20 ms |
7516 KB |
Output isn't correct |
62 |
Correct |
184 ms |
7568 KB |
Output is correct |
63 |
Correct |
80 ms |
7512 KB |
Output is correct |
64 |
Correct |
215 ms |
7560 KB |
Output is correct |
65 |
Correct |
140 ms |
7512 KB |
Output is correct |
66 |
Correct |
93 ms |
7512 KB |
Output is correct |
67 |
Correct |
89 ms |
7412 KB |
Output is correct |
68 |
Correct |
51 ms |
7516 KB |
Output is correct |
69 |
Correct |
46 ms |
7440 KB |
Output is correct |
70 |
Correct |
34 ms |
7664 KB |
Output is correct |
71 |
Correct |
31 ms |
7512 KB |
Output is correct |
72 |
Correct |
27 ms |
7512 KB |
Output is correct |
73 |
Correct |
45 ms |
7772 KB |
Output is correct |
74 |
Correct |
93 ms |
8016 KB |
Output is correct |
75 |
Correct |
66 ms |
7772 KB |
Output is correct |
76 |
Correct |
61 ms |
7768 KB |
Output is correct |
77 |
Correct |
69 ms |
7772 KB |
Output is correct |
78 |
Correct |
84 ms |
7820 KB |
Output is correct |
79 |
Correct |
79 ms |
8016 KB |
Output is correct |
80 |
Correct |
64 ms |
7812 KB |
Output is correct |
81 |
Correct |
74 ms |
7812 KB |
Output is correct |
82 |
Correct |
66 ms |
7816 KB |
Output is correct |
83 |
Correct |
83 ms |
7768 KB |
Output is correct |
84 |
Correct |
105 ms |
7772 KB |
Output is correct |
85 |
Correct |
84 ms |
7768 KB |
Output is correct |
86 |
Correct |
87 ms |
7776 KB |
Output is correct |
87 |
Correct |
96 ms |
7768 KB |
Output is correct |
88 |
Correct |
92 ms |
7512 KB |
Output is correct |
89 |
Correct |
124 ms |
7512 KB |
Output is correct |
90 |
Correct |
106 ms |
7720 KB |
Output is correct |
91 |
Correct |
121 ms |
7720 KB |
Output is correct |
92 |
Correct |
101 ms |
7720 KB |
Output is correct |