# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
910658 |
2024-01-18T06:55:45 Z |
CyberCow |
Zoo (COCI19_zoo) |
C++17 |
|
44 ms |
11352 KB |
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const ll N = 1005;
int a[N][N];
int obshi[N][N];
int color[N][N];
void solve()
{
int n, i, j, m, x, y, qan = 0;
cin >> n >> m;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < m; j++)
{
char c;
cin >> c;
if (c == 'T')
{
a[i][j] = 1;
qan++;
}
else if (c == 'B')
{
a[i][j] = 2;
qan++;
}
else
{
color[i][j] = 1;
}
}
}
int hanqan = 0, ans = 0;
queue<pair<int, int>> q, hajord;
hajord.push({ 0,0 });
color[0][0] = 1;
while (!hajord.empty())
{
ans++;
q = hajord;
while (!hajord.empty())
{
hajord.pop();
}
while (!q.empty())
{
x = q.front().first;
y = q.front().second;
q.pop();
if (x - 1 >= 0 && color[x - 1][y] == 0)
{
if (a[x - 1][y] == a[x][y])
q.push({ x - 1, y });
else
hajord.push({ x - 1, y });
color[x - 1][y] = 1;
}
if (x + 1 < n && color[x + 1][y] == 0)
{
if (a[x + 1][y] == a[x][y])
q.push({ x + 1, y });
else
hajord.push({ x + 1, y });
color[x + 1][y] = 1;
}
if (y - 1 >= 0 && color[x][y - 1] == 0)
{
if (a[x][y - 1] == a[x][y])
q.push({ x, y - 1 });
else
hajord.push({ x, y - 1});
color[x][y - 1] = 1;
}
if (y + 1 < m && color[x][y + 1] == 0)
{
if (a[x][y + 1] == a[x][y])
q.push({ x, y + 1 });
else
hajord.push({ x, y + 1 });
color[x][y + 1] = 1;
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message
zoo.cpp: In function 'void solve()':
zoo.cpp:60:9: warning: unused variable 'hanqan' [-Wunused-variable]
60 | int hanqan = 0, ans = 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 |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4568 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
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 |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4568 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
14 ms |
11100 KB |
Output is correct |
17 |
Correct |
14 ms |
11048 KB |
Output is correct |
18 |
Correct |
16 ms |
11100 KB |
Output is correct |
19 |
Correct |
15 ms |
11096 KB |
Output is correct |
20 |
Correct |
14 ms |
11100 KB |
Output is correct |
21 |
Correct |
36 ms |
10844 KB |
Output is correct |
22 |
Correct |
35 ms |
10844 KB |
Output is correct |
23 |
Correct |
34 ms |
10844 KB |
Output is correct |
24 |
Correct |
38 ms |
11148 KB |
Output is correct |
25 |
Correct |
41 ms |
11352 KB |
Output is correct |
26 |
Correct |
35 ms |
10948 KB |
Output is correct |
27 |
Correct |
34 ms |
10836 KB |
Output is correct |
28 |
Correct |
34 ms |
11004 KB |
Output is correct |
29 |
Correct |
44 ms |
11348 KB |
Output is correct |
30 |
Correct |
43 ms |
11096 KB |
Output is correct |