# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
798951 |
2023-07-31T07:57:18 Z |
yandabao |
Mecho (IOI09_mecho) |
C++14 |
|
236 ms |
11296 KB |
#include <iostream>
#include <vector>
#include <limits>
#include <map>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <climits>
#include <string.h>
#include <fstream>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi= vector<vector<int> >;
using vll = vector<long long>;
using vpi = vector<pair<int, int> >;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int, int>;
#define f first
#define s second
#define mp make_pair
//cin.tie(0)->sync_with_stdio(0);
int N, S;
vi dx, dy;
pi end;
vector<vector<char> > field;
vvi fromHive;
void BFS(int a, int b, vvi& fromMecho, int ad){
queue<pair<pair<int, int>, int> > q;
q.push(mp(mp(a, b), 0));
while(!q.empty()){
pair<pi, int> curr = q.front(); q.pop();
if(field[curr.f.f][curr.f.s] == 'T'){
continue;
}
if(fromHive[curr.f.f][curr.f.s] < curr.s/S + ad + (curr.s%S == 0 ? 0 : 1)){
continue;
}
if(fromMecho[curr.f.f][curr.f.s] > curr.s/S + ad + (curr.s%S == 0 ? 0 : 1)){
fromMecho[curr.f.f][curr.f.s] = curr.s/S + ad + (curr.s%S == 0 ? 0 : 1);
for (int i = 0; i < 4; i++)
{
if(curr.f.f + dx[i] < 0 || curr.f.f + dx[i] >= N || curr.f.s + dy[i] < 0 || curr.f.s >= N){
continue;
}
q.push(mp(mp(curr.f.f + dx[i], curr.f.s + dy[i]), curr.s + 1));
}
}
}
}
int main(){
cin >> N >> S;
dx = {-1, 1, 0, 0};
dy = {0, 0, -1, 1};
vi row(N, INFINITY);
fromHive.rsz(N);
field.rsz(N);
for (int i = 0; i < N; i++)
{
fromHive[i] = row;
field[i].rsz(N);
}
pi start, end;
vpi hive;
for (int i = 0; i < N; i++)
{
string str; cin >> str;
for (int j = 0; j < N; j++)
{
field[i][j] = str[j];
if(str[j] == 'M'){
start = mp(i, j);
}
if(str[j] == 'D'){
end = mp(i, j);
}
if(str[j] == 'H'){
hive.pb(mp(i, j));
}
}
}
queue<pair<pair<int, int>, int> > q;
for (int i = 0; i < sz(hive); i++)
{
q.push(mp(hive[i], 0));
}
while(!q.empty()){
pair<pi, int> curr = q.front(); q.pop();
if(field[curr.f.f][curr.f.s] != 'G' && field[curr.f.f][curr.f.s] != 'H'){
continue;
}
if(fromHive[curr.f.f][curr.f.s] > curr.s){
fromHive[curr.f.f][curr.f.s] = curr.s;
for (int i = 0; i < 4; i++)
{
if(curr.f.f + dx[i] < 0 || curr.f.f + dx[i] >= N || curr.f.s + dy[i] < 0 || curr.f.s + dy[i] >= N){
continue;
}
q.push(mp(mp(curr.f.f + dx[i], curr.f.s + dy[i]), curr.s + 1));
}
}
}
int lo = 0, hi = INT_MAX/2;
while(lo < hi){
int mid = (lo + hi + 1)/2;
vi row(N, INT_MAX);
vvi fromMecho(N);
for (int i = 0; i < N; i++)
{
fromMecho[i] = row;
}
BFS(start.f, start.s, fromMecho, mid);
// for (int i = 0; i < sz(fromMecho); i++)
// {
// for (int j = 0; j < N; j++)
// {
// cout << fromMecho[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
if(fromMecho[end.f][end.s] == INT_MAX){
hi = mid - 1;
} else {
lo = mid;
}
}
cout << lo;
// for (int i = 0; i < N; i++)
// {
// for (int j = 0; j < N; j++)
// {
// cout << fromHive[i][j] << " ";
// }
// cout << endl;
// }
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:67:15: warning: overflow in conversion from 'float' to 'std::vector<int>::value_type' {aka 'int'} changes value from '+Inff' to '2147483647' [-Woverflow]
67 | vi row(N, INFINITY);
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
144 ms |
6768 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
14 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Incorrect |
1 ms |
220 KB |
Output isn't correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Incorrect |
7 ms |
1420 KB |
Output isn't correct |
34 |
Correct |
8 ms |
1492 KB |
Output is correct |
35 |
Runtime error |
10 ms |
2796 KB |
Execution killed with signal 6 |
36 |
Incorrect |
8 ms |
1844 KB |
Output isn't correct |
37 |
Correct |
10 ms |
1864 KB |
Output is correct |
38 |
Correct |
47 ms |
1916 KB |
Output is correct |
39 |
Incorrect |
10 ms |
2260 KB |
Output isn't correct |
40 |
Correct |
11 ms |
2260 KB |
Output is correct |
41 |
Runtime error |
18 ms |
4360 KB |
Execution killed with signal 6 |
42 |
Incorrect |
16 ms |
2692 KB |
Output isn't correct |
43 |
Correct |
15 ms |
2712 KB |
Output is correct |
44 |
Correct |
88 ms |
2812 KB |
Output is correct |
45 |
Incorrect |
17 ms |
3276 KB |
Output isn't correct |
46 |
Correct |
15 ms |
3320 KB |
Output is correct |
47 |
Runtime error |
23 ms |
6252 KB |
Execution killed with signal 6 |
48 |
Incorrect |
18 ms |
3892 KB |
Output isn't correct |
49 |
Correct |
18 ms |
3796 KB |
Output is correct |
50 |
Correct |
113 ms |
3992 KB |
Output is correct |
51 |
Incorrect |
21 ms |
4488 KB |
Output isn't correct |
52 |
Correct |
26 ms |
4448 KB |
Output is correct |
53 |
Runtime error |
34 ms |
8592 KB |
Execution killed with signal 6 |
54 |
Incorrect |
27 ms |
5152 KB |
Output isn't correct |
55 |
Correct |
31 ms |
5184 KB |
Output is correct |
56 |
Correct |
155 ms |
5212 KB |
Output is correct |
57 |
Incorrect |
32 ms |
5836 KB |
Output isn't correct |
58 |
Correct |
30 ms |
5876 KB |
Output is correct |
59 |
Runtime error |
60 ms |
11296 KB |
Execution killed with signal 6 |
60 |
Incorrect |
29 ms |
6604 KB |
Output isn't correct |
61 |
Correct |
30 ms |
6612 KB |
Output is correct |
62 |
Correct |
207 ms |
6832 KB |
Output is correct |
63 |
Correct |
138 ms |
6720 KB |
Output is correct |
64 |
Correct |
236 ms |
6724 KB |
Output is correct |
65 |
Correct |
231 ms |
6740 KB |
Output is correct |
66 |
Incorrect |
175 ms |
6936 KB |
Output isn't correct |
67 |
Incorrect |
164 ms |
6808 KB |
Output isn't correct |
68 |
Correct |
76 ms |
6756 KB |
Output is correct |
69 |
Correct |
70 ms |
6800 KB |
Output is correct |
70 |
Correct |
66 ms |
6768 KB |
Output is correct |
71 |
Correct |
75 ms |
6844 KB |
Output is correct |
72 |
Incorrect |
63 ms |
6880 KB |
Output isn't correct |
73 |
Incorrect |
135 ms |
6828 KB |
Output isn't correct |
74 |
Correct |
97 ms |
6800 KB |
Output is correct |
75 |
Correct |
116 ms |
6744 KB |
Output is correct |
76 |
Correct |
107 ms |
6820 KB |
Output is correct |
77 |
Correct |
107 ms |
6820 KB |
Output is correct |
78 |
Incorrect |
128 ms |
6804 KB |
Output isn't correct |
79 |
Correct |
88 ms |
6752 KB |
Output is correct |
80 |
Correct |
103 ms |
6744 KB |
Output is correct |
81 |
Correct |
122 ms |
6856 KB |
Output is correct |
82 |
Correct |
107 ms |
6828 KB |
Output is correct |
83 |
Correct |
135 ms |
6720 KB |
Output is correct |
84 |
Correct |
121 ms |
6772 KB |
Output is correct |
85 |
Correct |
122 ms |
6972 KB |
Output is correct |
86 |
Correct |
129 ms |
6712 KB |
Output is correct |
87 |
Correct |
125 ms |
6780 KB |
Output is correct |
88 |
Correct |
136 ms |
6768 KB |
Output is correct |
89 |
Correct |
159 ms |
6872 KB |
Output is correct |
90 |
Correct |
148 ms |
6700 KB |
Output is correct |
91 |
Correct |
137 ms |
6720 KB |
Output is correct |
92 |
Correct |
138 ms |
6720 KB |
Output is correct |