Advertisement
TAHMID37

prottyoy madafaqqa

Oct 26th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define debug 0
  22. #define MAXN   100001
  23. #define ar array
  24. #define lb lower_bound
  25. #define ub upper_bound
  26. const int mxN=2e5;
  27. const int MOD=1e9+7;
  28. template<typename ForwardIterator, typename T>
  29. ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
  30. {auto it = std::lower_bound (first, last, value);
  31. return (it == first ? last : --it);}
  32. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
  33. {
  34.     return (a.second < b.second);
  35. }
  36. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  37. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  38. ll a[6560][6560];
  39.  
  40. bool flood_fill(ll sr,ll sc,ll nc,ll pre,ll n,ll m)
  41. {
  42.     if(sr>=n||sc>=m||sr<0||sc<0)
  43.         return false;
  44.     if(a[sr][sc]!=pre)
  45.         return false;
  46.     if(a[sr][sc]==pre)
  47.     {
  48.         a[sr][sc]=nc;
  49.     }
  50.  
  51.     flood_fill(sr-1,sc,nc,pre,n,m);//UP;
  52.     flood_fill(sr+1,sc,nc,pre,n,m);//down;
  53.     flood_fill(sr,sc+1,nc,pre,n,m);//right;
  54.     flood_fill(sr,sc-1,nc,pre,n,m);//left;
  55.  
  56. }
  57.  
  58. int main()
  59. {
  60.     ll n,m,i,j;
  61.     cin>>n>>m;
  62.  
  63.     ll sr,sc,nc;
  64.     cin>>sr>>sc>>nc;
  65.  
  66.     for(i=0;i<n;i++)
  67.     {
  68.         for(j=0;j<m;j++)
  69.         {
  70.             cin>>a[i][j];
  71.         }
  72.     }
  73.  
  74.     ll prev_c=a[sr-1][sc-1];
  75.     ll pre=prev_c;
  76.  
  77.     flood_fill(sr-1,sc-1,nc,pre,n,m);
  78.  
  79.     for(i=0;i<n;i++)
  80.     {
  81.         for(j=0;j<m;j++)
  82.         {
  83.             cout<<a[i][j]<<" ";
  84.         }
  85.         cout<<endl;
  86.     }
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement