For problem 
https://codejam.withgoogle.com/codejam/contest/4334486/dashboard#s=p4

I was getting two types of status => [Wrong answer] or [Runtime Error]

After commenting out final Master node part which sums up all the answers
it should definitely be a 'Wrong Answer' but since Runtime Error Code is not 
fixed. It should show 'Runtime Error' right???.

In short 
---
Commenting out a part which should not affect the RTE is causing status change 
to RTE to WA.
--

What could be the possible cause,, any hints?


Following is end of part of my code
-----------------------------
           
                .....//Execute for every Node
                .....
                assert(extraCrates[upper-lower-1]==0);  //RTE is not because of 
this

                PutLL(0, mineCost);
                Send(0);

         }
         // return 0;
        if(my_id==0) {
                //Main Node


                //Existence of this Part => RTE
                //Non-Existence of this Part => WA
                
                //FROM HERE

                for (ll i = 0; i < nodes; ++i)
                {
                        Receive(i);
                        ll a = GetLL(i);
                        totalCost=(totalCost+a)%MOD;
                }
                cout<<totalCost;
                //TILL HERE
        }


******************** FULL CODE for reference **************

#include <bits/stdc++.h>
#include <message.h>
//1hr 40 min

#include "crates.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::vector<int> vi;

#define forv(it,m) for (auto it = (m).begin(); it != (m).end(); ++it)
#define rep(i,n) for (int i=0;i<n;i++)
#define endl '\n' 
#define mp make_pair
#define pb(x) push_back((x))
#define what_is(x) cerr << #x << " is " << (x) << endl;

ll MOD = 1e9+7;
ll INF = LLONG_MAX/4;

vector<string> &split(const std::string &s, char delim, vector<string> &e) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim))
        e.push_back(item);
    return e;
}


ll Pow(ll a ,ll b ,ll Mo){
    ll ans = 1;
    for (; b; b >>= 1, a = a * a % Mo)
        if (b&1) ans = ans * a % Mo;
    return ans;
}


ll nCr(ll n,ll r) {
    static ll MAXF = 1e6;
    static std::vector<ll> fact(MAXF,1);
    for (int i = 1; i < MAXF; ++i)  fact[i]=(fact[i-1]*i)%MOD;
    MAXF=0;
    return (fact[n]*Pow((fact[r]*fact[n-r])%MOD,MOD-2,MOD))%MOD;
}

vector<int> Zfunc(string &s) {
    int n=s.length();
    vector<int> z(n,0);
    for(int i=1,l=0,r=0;i<n;i++) {
        if(i<=r) 
            z[i] = min(z[i-l],r-i+1);
        while(i+z[i]<n && s[i+z[i]]==s[z[i]])
            z[i]++;
        if(r<i+z[i]-1)
            l=i,r=i+z[i]-1;
    }
    return z;
}

ll solve() {
        
        
        return 0;
}



int main(int argc, char const *argv[])
{
        std::ios::sync_with_stdio(false);cin.tie(0);
        // cout<<fixed<<setprecision(1);
        
        ll nodes = NumberOfNodes();
        ll my_id = MyNodeId();

        ll N = GetNumStacks();

        std::vector<ll> mycrates;
        if(nodes>N)
                nodes=N;
        if(my_id>=nodes) {
                cerr<<"Exiting\n";
                return 0;
        }
        
        ll lower = N*my_id/nodes;
        ll upper = N*(my_id+1)/nodes;

        {
                mycrates.resize(upper-lower);
                ll sum = 0;
                for (int i = 0; i < upper-lower; ++i)
                {
                        // assert(lower+i<N);
                        mycrates[i]=GetStackHeight(lower+i+1);
                        // cerr<<" > "<<mycrates[i]<<endl;
                        sum+=mycrates[i];;
                }
                //GetStackHeight
                //Every Node computation
                PutLL(0, sum);
                PutLL(0, upper-lower);
                Send(0);
        
        }
        ll totalCost = 0;
        ll mineCost = 0;

        if(my_id==0) {
                //Main Node
                ll totalCrates = 0;
                std::vector<ll> cntCrates(nodes);
                std::vector<ll> cumStacks(nodes+1,0);
                std::vector<ll> extraCrates(nodes);
                for (ll i = 0; i < nodes; ++i)
                {
                        Receive(i);
                        ll a = GetLL(i);
                        cumStacks[i+1]=cumStacks[i]+GetLL(i);
                        cntCrates[i]=a;
                        totalCrates+=a;
                }
                ll extraones = totalCrates%N;
                ll avg = totalCrates/N;
                // cerr<<extraones<<" "<<avg<<endl;
                ll assertSum = 0;
                std::vector<ll> sendToRight(nodes,0);
                std::vector<ll> ReceiveFromLeft(nodes,0);

                for (int i = 0; i < nodes; ++i)
                {
                        ll cratesLeft = cumStacks[i];
                        ll sz = cumStacks[i+1]-cumStacks[i];
                        ll mx = sz*avg;
                        ll here =max( min(extraones-cratesLeft,sz),0LL);
                        extraCrates[i]=cntCrates[i]-(avg*sz+here);
                        assertSum+=extraCrates[i];
                        // cerr<<" HEREGood  "<<(avg*sz+here)<<endl;
                        // cerr<<"+ "<<extraCrates[i]<<" from node "<<i<<endl;
                }
                assert(assertSum == 0);

                for (int i = 0; i < nodes-1; ++i)
                {
                        ll diff = extraCrates[i];
                        sendToRight[i] += diff;
                        ReceiveFromLeft[i+1] += diff;
                        extraCrates[i+1]+=extraCrates[i];
                        totalCost=(totalCost + abs(diff))%MOD;
                        // cerr<<"TR "<<sendToRight[i]<<" FR 
"<<ReceiveFromLeft[i]<<endl;
                }

                assert(extraCrates[nodes-1]==0);
                // std::vector<ll> needCratesTowardRight(nodes+1,0);
                // for (int i = nodes-1; i >= 0; --i)
                // {
                //      
needCratesTowardRight[i]=needCratesTowardRight[i+1]-extraCrates[i];
                // }

                // //left to right
                // for (int i = 0; i < nodes-1; ++i)
                // if(extraCrates[i]>0 && needCratesTowardRight[i+1]>0)  {
                //      ll tns =  min(needCratesTowardRight[i+1]
                // }

                for (ll i = 0; i < nodes; ++i)
                {
                        PutLL(i,extraones);
                        PutLL(i,avg);
                        PutLL(i,sendToRight[i]);
                        PutLL(i,ReceiveFromLeft[i]);
                        Send(i);
                }
                
        }
        // return 0;
        ll mineextra;

        ll avg;
         {
                ///all
                Receive(0);
                ll extraones = GetLL(0);
                avg = GetLL(0);
                mineextra = max(min(extraones-lower,upper-lower),0LL);
                ll sendRight = GetLL(0);
                ll recLeft = GetLL(0);
                //cerr<<"Extta To "<<mineextra<<endl;
                std::vector<ll> extraCrates(upper-lower);
                
                for (int i = 0; i < upper-lower; ++i)
                {
                        extraCrates[i]=mycrates[i]-avg;
                        if(i<mineextra)
                                extraCrates[i]--;
                //cerr<<"MExtra "<<extraCrates[i]<<" original 
"<<mycrates[i]<<endl;
                }

                //cerr<<"To Right "<<sendRight <<" From Left "<<recLeft<<endl;
                if(abs(sendRight)!=0) {
                        extraCrates[upper-lower-1]-=sendRight;
                }

                if(abs(recLeft)!=0) {
                        extraCrates[0]+=recLeft;
                }


                mineCost = 0;
                for (int i = 0; i < upper-lower-1; ++i)
                {
                        ll diff = extraCrates[i];
                        extraCrates[i+1]+=diff;
                        extraCrates[i]=0;
                        mineCost=(mineCost +  abs(diff))%MOD;
                        //cerr<<extraCrates[i]<<endl;
                }
                // cerr<<(upper-lower-1)<<endl;
                assert(extraCrates[upper-lower-1]==0);

                PutLL(0, mineCost);
                Send(0);

         }
         // return 0;
        if(my_id==0) {
                //Main Node
                for (ll i = 0; i < nodes; ++i)
                {
                        Receive(i);
                        ll a = GetLL(i);
                        totalCost=(totalCost+a)%MOD;
                }
                // cout<<totalCost;
        }
        return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/6634d8e9-1c3c-4c19-9923-77a48ec00c3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to