# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201320 | kayu | Emacs (COCI20_emacs) | C++14 | 6 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//
int n, m;
vector<string> v;
vector<vector<bool>> vis;
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
bool check(int x, int y)
{
return (x >= 0 && x < n && y >= 0 && y < m);
}
void dfs(int x, int y)
{
if(!check(x, y)) return;
if(v[x][y] == '.') return;
if(vis[x][y]) return;
vis[x][y] = true;
for(int i=0;i<8;i++)
{
dfs(x+dx[i], y+dy[i]);
}
}
int32_t main()
{
fastio;
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
cin >> n >> m;
v.resize(n);
for(int i=0;i<n;i++)
cin >> v[i];
vis.assign(n, vector<bool>(m, false));
int ans = 0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(v[i][j] == '*' && vis[i][j] == false)
{
dfs(i, j);
ans++;
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |