Please Explain Game Of Life Codeforces

Hello, Please Explain Me Game Of Life From Codeforces Deltix Round
I Am Not Able To Solve It

#Link

@cubefreak777 @sudo_s @suman_18733097
Thanks In Advance
Krishna Wadhwani

What you did not understand?

I Have Understood The Question But I Am Not Able To Code It

  • Here is my code: :slight_smile:
#include <iostream>
#include <cmath>
#include <algorithm>
#include<bits/stdc++.h>
#include <stdio.h>
#include <vector>
#define lli long long int
#define ll long long
using namespace std;
#define tc lli tc;scanf("%lld",&tc);while(tc--)
#define FOR(i, a, b) for (lli i = (a); i <= (b); i++)
#define FORN(i, a, b) for (lli i = (a); i < (b); i++)
//defined mod when a is either negative or positive
#define mod(a,b) (((a%b)+b)%b)
// endl forces a unnecessary flush so it's slow
#define endl "\n"
#define ld long double
// output_decimal(a) used for output of decimal precision upto 'a'
#define output_decimal(a) cout.setf(ios::fixed); cout.precision(a);
//ccmod is codechef mod and a prime number
#define ccmod (int(1e9+7))
//we need to ignore cin before taking string input if we previously used it 
#define later_strin(s) cin.ignore();getline(cin,s);
#define fio ios::sync_with_stdio(0);cin.tie(0);
void solve();

// GCD or HCF of 2 numbers
long long int gcd(lli a, lli b) 
{ 
  if (b == 0) 
    return a; 
  return gcd(b, a % b); 
}


int main(){ 
cin.tie(0);
cout.tie(0);
tc{
solve();
}
return 0;
}

// Write CODE here without Test case---#
void solve(){
  int n,m;
  cin>>n>>m;
  string s,s1;
  cin>>s;
  s1=s;
  FORN(j,0,min(n,m)){
    FORN(i,0,n){
      if(s[i]=='0' and (s[i-1]!='1' and s[i+1]=='1')){
        s1[i]='1';
      }
      else if(s[i]=='0' and (s[i-1]=='1' and s[i+1]!='1')){
        s1[i]='1';
      }
    }
    s=s1;
  }

  cout<<s<<endl;
}
1 Like

I hope it will be helpful. :slight_smile:

Thanks, @anon73130069