Submission #279660

#TimeUsernameProblemLanguageResultExecution timeMemory
279660PedroBigManEmacs (COCI20_emacs)C++14
50 / 50
1 ms640 KiB
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <list> #include <iomanip> #include <stdlib.h> #include <time.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=a; i<b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define whole(x) x.begin(),x.end() #define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl #define INF 5000000000000000000LL template<class A=ll> void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;} template<class A=ll> void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} ll N,M; vector<vector<bool> > visited; vector<vector<ll> > a; void DFS(ll x, ll y) { if(visited[x][y]) {return;} visited[x][y]=true; if(x>0 && !visited[x-1][y] && a[x-1][y]==1) {DFS(x-1,y);} if(x<N-1 && !visited[x+1][y] && a[x+1][y]==1) {DFS(x+1,y);} if(y>0 && !visited[x][y-1] && a[x][y-1]==1) {DFS(x,y-1);} if(y<M-1 && !visited[x][y+1] && a[x][y+1]==1) {DFS(x,y+1);} } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N>>M; vector<bool> xxx; vector<ll> xx; REP(i,0,M) {xx.pb(0); xxx.pb(false);} REP(i,0,N) {a.pb(xx); visited.pb(xxx);} REP(i,0,N) { REP(j,0,M) { char c; cin>>c; if(c=='*') {a[i][j]=1;} } } ll ans=0LL; REP(i,0,N) {REP(j,0,M) {if(a[i][j]==1 && !visited[i][j]) {DFS(i,j); ans++;}}} cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...