Submission #867292

# Submission time Handle Problem Language Result Execution time Memory
867292 2023-10-28T06:15:13 Z Reyam Emacs (COCI20_emacs) C++14
50 / 50
1 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fix fixed<<setprecision(20)
#define endl'\n'
#define c(x) cout<<x<<endl
#define int ll
 //int a[200090],pre[200090],suf[200090];
 int mx[]={0,0,-1,1},my[]={-1,1,0,0};
 char a[200][200];
 bool vis[200][200];
 int n,m;
 bool inside(int i,int j){
 return (i&&i<=n&&j&&j<=m);
    }
    void dfs (int i,int j){
        vis[i][j]=1;
        for(int k=0;k<4;k++){
            int nx=i+mx[k],ny=j+my[k];
            if(inside(nx,ny)&& !vis[nx][ny]&& a[nx][ny]=='*') { vis[nx][ny]=1;
            dfs(nx,ny);}
        }
    }

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   cin>>n;
  cin>>m;
   int cnt=0;
   for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>a[i][j];
   for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
   {if(a[i][j]=='*'&& !vis [i][j]){
    dfs(i,j); cnt++;
   }}
   cout<<cnt<<endl;
}

Compilation message

emacs.cpp:7:9: warning: ISO C++11 requires whitespace after the macro name
    7 | #define endl'\n'
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 472 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct