# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
340047 |
2020-12-26T16:17:32 Z |
sinamhdv |
Zoo (COCI19_zoo) |
C++11 |
|
56 ms |
4332 KB |
// ojuz COCI19_zoo
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 1100
vector<pii> ngb = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int n, m;
char grid[MAXN][MAXN];
bool mark[MAXN][MAXN];
vector<pii> cur, nxt;
char clet;
void dfs(int x, int y)
{
mark[x][y] = true;
for (pii p : ngb)
{
int ux = x + p.fr;
int uy = y + p.sc;
if (ux >= n || ux < 0 || uy >= m || uy < 0)
{
continue;
}
if (mark[ux][uy] || grid[ux][uy] == '*')
{
continue;
}
if (grid[ux][uy] == clet)
{
dfs(ux, uy);
}
else
{
nxt.pb(mp(ux, uy));
}
}
}
int32_t main(void)
{
fast_io;
cin >> n >> m;
FOR(i, 0, n)
{
FOR(j, 0, m)
{
cin >> grid[i][j];
}
}
cur.pb(mp(0, 0));
clet = grid[0][0];
int ans = 0;
while (!cur.empty())
{
ans++;
for (pii v : cur)
{
if (!mark[v.fr][v.sc])
{
dfs(v.fr, v.sc);
}
}
cur = nxt;
nxt.clear();
clet = (clet == 'B' ? 'T' : 'B');
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
620 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
620 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
620 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
20 ms |
4332 KB |
Output is correct |
17 |
Correct |
20 ms |
3948 KB |
Output is correct |
18 |
Correct |
20 ms |
4076 KB |
Output is correct |
19 |
Correct |
22 ms |
4332 KB |
Output is correct |
20 |
Correct |
20 ms |
4204 KB |
Output is correct |
21 |
Correct |
52 ms |
3564 KB |
Output is correct |
22 |
Correct |
53 ms |
3564 KB |
Output is correct |
23 |
Correct |
54 ms |
3564 KB |
Output is correct |
24 |
Correct |
55 ms |
3692 KB |
Output is correct |
25 |
Correct |
54 ms |
3692 KB |
Output is correct |
26 |
Correct |
55 ms |
3564 KB |
Output is correct |
27 |
Correct |
52 ms |
3564 KB |
Output is correct |
28 |
Correct |
52 ms |
3564 KB |
Output is correct |
29 |
Correct |
55 ms |
3820 KB |
Output is correct |
30 |
Correct |
56 ms |
3692 KB |
Output is correct |