# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102469 |
2024-10-18T07:45:52 Z |
HasanV11010238 |
Zoo (COCI19_zoo) |
C++17 |
|
358 ms |
139152 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long long
#define INF 1000000000
vector<vector<vector<int>>> v;
int bfs(int n, int st){
vector<int> di(n, INF);
deque<int> q;
di[st] = 0;
q.push_back(st);
while (!q.empty()){
int x = q.front();
q.pop_front();
for (auto el : v[x]){
if (di[el[0]] > di[x] + el[1]){
di[el[0]] = di[x] + el[1];
if (el[1] == 0){
q.push_front(el[0]);
}
else{
q.push_back(el[0]);
}
}
}
}
int ans = 0;
for (int i = 0; i < n; i++){
if (di[i] == INF) continue;
ans = max(ans, di[i]);
}
return ans;
}
int main(){
int n, m;
cin>>n>>m;
map<char, int> ma;
ma['B'] = 0;
ma['T'] = 1;
v.resize(n * m);
vector<string> s(n);
for (int i = 0; i < n; i++){
cin>>s[i];
for (int j = 0; j < m; j++){
if (s[i][j] == '*') continue;
int v1 = i * m + j;
if (i != 0 && s[i - 1][j] != '*'){
int v2 = (i - 1) * m + j;
v[v1].push_back({v2, ma[s[i][j]] ^ ma[s[i - 1][j]]});
v[v2].push_back({v1, ma[s[i][j]] ^ ma[s[i - 1][j]]});
}
if (j != 0 && s[i][j - 1] != '*'){
int v2 = i * m + j - 1;
v[v1].push_back({v2, ma[s[i][j]] ^ ma[s[i][j - 1]]});
v[v2].push_back({v1, ma[s[i][j]] ^ ma[s[i][j - 1]]});
}
}
}
cout<<bfs(n * m, 0) + 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
1364 KB |
Output is correct |
6 |
Correct |
5 ms |
1620 KB |
Output is correct |
7 |
Correct |
3 ms |
1620 KB |
Output is correct |
8 |
Correct |
3 ms |
1600 KB |
Output is correct |
9 |
Correct |
3 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1620 KB |
Output is correct |
11 |
Correct |
3 ms |
1364 KB |
Output is correct |
12 |
Correct |
3 ms |
1620 KB |
Output is correct |
13 |
Correct |
3 ms |
1528 KB |
Output is correct |
14 |
Correct |
3 ms |
1364 KB |
Output is correct |
15 |
Correct |
3 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
1364 KB |
Output is correct |
6 |
Correct |
5 ms |
1620 KB |
Output is correct |
7 |
Correct |
3 ms |
1620 KB |
Output is correct |
8 |
Correct |
3 ms |
1600 KB |
Output is correct |
9 |
Correct |
3 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1620 KB |
Output is correct |
11 |
Correct |
3 ms |
1364 KB |
Output is correct |
12 |
Correct |
3 ms |
1620 KB |
Output is correct |
13 |
Correct |
3 ms |
1528 KB |
Output is correct |
14 |
Correct |
3 ms |
1364 KB |
Output is correct |
15 |
Correct |
3 ms |
1364 KB |
Output is correct |
16 |
Correct |
70 ms |
44364 KB |
Output is correct |
17 |
Correct |
67 ms |
45644 KB |
Output is correct |
18 |
Correct |
63 ms |
45488 KB |
Output is correct |
19 |
Correct |
76 ms |
52048 KB |
Output is correct |
20 |
Correct |
58 ms |
45148 KB |
Output is correct |
21 |
Correct |
332 ms |
131916 KB |
Output is correct |
22 |
Correct |
331 ms |
132032 KB |
Output is correct |
23 |
Correct |
322 ms |
133452 KB |
Output is correct |
24 |
Correct |
356 ms |
139152 KB |
Output is correct |
25 |
Correct |
333 ms |
136268 KB |
Output is correct |
26 |
Correct |
358 ms |
135244 KB |
Output is correct |
27 |
Correct |
332 ms |
131032 KB |
Output is correct |
28 |
Correct |
319 ms |
130368 KB |
Output is correct |
29 |
Correct |
313 ms |
137928 KB |
Output is correct |
30 |
Correct |
312 ms |
136696 KB |
Output is correct |