Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define debug 0
- #define MAXN 100001
- #define ar array
- #define lb lower_bound
- #define ub upper_bound
- const int mxN=2e5;
- const int MOD=1e9+7;
- template<typename ForwardIterator, typename T>
- ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
- {auto it = std::lower_bound (first, last, value);
- return (it == first ? last : --it);}
- bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
- {
- return (a.second < b.second);
- }
- #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
- #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
- ll a[6560][6560];
- bool flood_fill(ll sr,ll sc,ll nc,ll pre,ll n,ll m)
- {
- if(sr>=n||sc>=m||sr<0||sc<0)
- return false;
- if(a[sr][sc]!=pre)
- return false;
- if(a[sr][sc]==pre)
- {
- a[sr][sc]=nc;
- }
- flood_fill(sr-1,sc,nc,pre,n,m);//UP;
- flood_fill(sr+1,sc,nc,pre,n,m);//down;
- flood_fill(sr,sc+1,nc,pre,n,m);//right;
- flood_fill(sr,sc-1,nc,pre,n,m);//left;
- }
- int main()
- {
- ll n,m,i,j;
- cin>>n>>m;
- ll sr,sc,nc;
- cin>>sr>>sc>>nc;
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- cin>>a[i][j];
- }
- }
- ll prev_c=a[sr-1][sc-1];
- ll pre=prev_c;
- flood_fill(sr-1,sc-1,nc,pre,n,m);
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement