CHEFHACK - Editorial

Thank you Anton! I will try that.

I tried vector but they slowed down the execution. So, I went with allocating memory on the heap using new. Submitted with correct answer! Thank you!

Very nice editorial @anton_lunyov
I loved the fact that you right away told the people the test cases on which their code was going south. I miss that in other editorials. I like codeforces as they show us the test cases where one’s code goes wrong and I really miss this in codechef.
Also you gave the links of sample problems and I very much liked this gesture of yours.

1 Like

Hey,Can Some one check my solution.It does not pass sys test.

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define lld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define precise(ans)  cout<<fixed<<setprecision(15)<<ans
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<vi>      vvi;
typedef vector<vvi>    vvvi;
typedef vector<ll>      vl;
typedef vector<vl>      vvl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
const int mod = 1000000007;
#define PI 3.1415926535897932384626
const int M=1e9+7;
const int N=1e7+10;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vector<bool> prime(N, true);
vector<ll> aa(N,0);
void primesieve(){
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <N; i++)
    {
        if (prime[i] == true)
        {
            aa[i]=1;
            for (int j = i * i; j < N; j = j + i)
            {
                prime[j] = false;
            }
        }
    }
    for(ll i=2;i<N;i++){
      aa[i]+=aa[i-1];
    }
}
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

void dfs(vector<vector<ll>>& bb,int i,int j,int n,vector<vector<int>>& vis){
  for(ll k=0;k<4;k++){
    ll x=i+dx[k],y=j+dy[k];
    if(x>=0 && y>=0 && x<n && y<n && vis[x][y]==0 && (!prime[bb[x][y]])){
     if((bb[i][j]&1)==(bb[x][y]&1)){
        vis[x][y]=1;
        dfs(bb,x,y,n,vis);
      }
    }
  }
}

void solve() {
  ll n;
  cin>>n;
  vector<vector<ll>> bb(n,vector<ll>(n));
  vector<vector<int>> vis(n,vector<int>(n,0));
  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
      cin>>bb[i][j];
    }
  }
  
  ll ans=0;
  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
      if(vis[i][j]==1){
        cout<<"-1 ";
        continue;
      }
      vis[i][j]=1;
      if(prime[bb[i][j]]){
        cout<<(aa[bb[i][j]]-1)<<" ";
        ans+=(aa[bb[i][j]]-1);
      }else{
        if(bb[i][j]%2==0){
          cout<<(bb[i][j]/2)<<" ";
          ans+=(bb[i][j]/2);
        }else{
          cout<<((bb[i][j]+1)/2)+1<<" ";
          ans+=((bb[i][j]+1)/2)+1;
        }
        dfs(bb,i,j,n,vis);
      }
    }
    cout<<endl;
  }
  cout<<ans<<endl;

}


int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll  t;
  t = 1;
  cin >> t;
  primesieve();
  while (t--) {
    solve();

  }

  return 0;
}

Does anyone know what code this is
+221 and #3 is important
Code is used to generate fake numbers and hide real ones

+221 76 324 94 53

0469 884 738 Correct number is 0466 424 748
0472 709 087 correct number unknown
0473 140 950 correct number unknown
0473 545 385 correct number unknown
0474 035 470 correct number unknown
0474 206 394 correct number unknown
0474 858 013 correct number unknown
0475 145 637 correct number is 0475 361 745