# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440433 | Abrar_Al_Samit | Emacs (COCI20_emacs) | C++17 | 4 ms | 332 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
void PlayGround() {
int n, m; cin >> n >> m;
vector<string>g(n);
for(string& row : g) cin >> row;
int ans = 0;
auto BFS = [&] (int i, int j) {
queue<pair<int,int>>q;
q.push({i, j});
auto valid = [=] (int x, int y) {
return x>-1 && y>-1 && x<n && y<m && g[x][y]=='*';
};
while(!q.empty()) {
pair<int,int>cur = q.front(); q.pop();
if(g[cur.first][cur.second]!='*') continue;
g[cur.first][cur.second] = '.';
int dx[] {1, -1, 0, 0};
int dy[] {0, 0, 1, -1};
for(int k=0; k<4; ++k) {
int new_i = cur.first + dx[k], new_j = cur.second + dy[k];
if(valid(new_i, new_j))
q.push({new_i, new_j});
}
}
};
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
if(g[i][j]=='*') {
BFS(i, j), ++ans;
}
}
}
cout << ans << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
PlayGround();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |