# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
445775 |
2021-07-19T14:16:26 Z |
Chy_Chy |
Zoo (COCI19_zoo) |
C++14 |
|
1 ms |
332 KB |
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp> // common file
#include<ext/pb_ds/tree_policy.hpp> // including tree_order_statistics_node_update
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(), (x).end()
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define sz(x) (int)((x).size())
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define nn "\n"
// bit manipulation
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#define ordered_set tree<int, null_type, less<int> , rb_tree_tag, tree_order_statistics_node_update>
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) {
res = a * res;
}
a = a * a;
b >>= 1;
}
return res;
}
void fast_io()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
int gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b);}
int lcm(int a, int b) {return a / gcd(a, b) * b;}
const int N = 1005;
char grid[N][N];
bool vis[N][N];
int r, c;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool valid(int x, int y, char ch) {
if (x >= 0 && x < r && y >= 0 && y < c && grid[x][y] == ch && !vis[x][y]) {
return true;
}
return false;
}
void dfs(int sx, int sy, char ch) {
vis[sx][sy] = 1;
// debug(ch);
for (int i = 0; i < 4; i++) {
int tx = sx + dx[i];
int ty = sy + dy[i];
if (valid(tx, ty, ch)) {
dfs(tx, ty, ch);
}
}
}
void KhelaFinal() {
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> grid[i][j];
vis[i][j] = false;
}
}
int ans = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (grid[i][j] != '*' && !vis[i][j]) {
// debug(i);
// debug(j);
dfs(i, j, grid[i][j]);
ans++;
}
}
}
cout << ans << endl;
}
signed main()
{
fast_io();
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
int t = 1;
// cin >> t;
while (t--) {
KhelaFinal();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |