You are viewing a single comment's thread. Return to all comments →
Can u please point out the error or make necessary corrections?
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long int #define mod 10000007 #define rep(a,b,c) for(int i=a;i<=b;i+=c) #define repi(a,b,c) for(int i=a;i>=b;i-=c) #define lb lower_bound #define ub upper_bound #define pushb push_back #define popb pop_back using namespace std; char f[101][101]; bool v[101][101]; int k,Count=0; void dfs(int n,int m,int i,int j) { v[i][j]=1; if(f[i][j+1]=='*') return ; else if(f[i][j-1]=='*') return ; else if(f[i-1][j]=='*') return ; else if(f[i+1][j]=='*') return ; if(!v[i][j-1]&&!v[i+1][j]&&f[i][j-1]=='.'&&f[i+1][j]=='.') Count++; else if(!v[i][j-1]&&!v[i-1][j]&&f[i][j-1]=='.'&&f[i-1][j]=='.') Count++; else if(!v[i][j-1]&&!v[i][j+1]&&f[i][j-1]=='.'&&f[i][j+1]=='.') Count++; else if(!v[i+1][j]&&!v[i][j+1]&&f[i+1][j]=='.'&&f[i][j+1]=='.') Count++; else if(!v[i+1][j]&&!v[i-1][j]&&f[i+1][j]=='.'&&f[i-1][j]=='.') Count++; else if(!v[i][j+1]&&!v[i-1][j]&&f[i][j+1]=='.'&&f[i-1][j]=='.') Count++; if(!v[i+1][j]&&f[i+1][j]=='.') dfs(n,m,i+1,j); if(!v[i-1][j]&&f[i-1][j]=='.') dfs(n,m,i-1,j); if(!v[i][j-1]&&f[i][j-1]=='.') dfs(n,m,i,j-1); if(!v[i][j+1]&&f[i][j+1]=='.') dfs(n,m,i,j+1); } int main() { int t; cin>>t; while(t--) { int n,m,i,j; cin>>n>>m; Count=0; memset(f,'X',sizeof(f)); memset(v,false,sizeof(v)); for(i=1;i<=n;i++) for(j=1;j<=m;j++) { cin>>f[i][j]; } cin>>k; int I,J; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { if(f[i][j]=='M') { I=i; J=j; if(!v[i][j]) { dfs(n,m,i,j); } } } if(Count==k) cout<<"Impressed"<<endl; else cout<<"Oops!"<<endl; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Count Luck
You are viewing a single comment's thread. Return to all comments →
Can u please point out the error or make necessary corrections?