Hi everyone!
I'm getting runtime error on my code for problem sandwich and I cannot test
it on my local machine as I didn't figure out how to make the tester work
on Windows 8
Here's my code, if anyone can tell me why is it giving me runtime error I'd
appreciate it. I tried everything and it still gives me runtime error.
Thanks in advance!
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<sstream>
#include<queue>
#include<vector>
#include<message.h>
#include "sandwich.h"
using namespace std;
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
long long sum(vector<long long> &vec)
{
long long res = 0;
for(int i=0;i<vec.size();i++)
res += vec[i];
return res;
}
long long solve(vector<long long> vec)
{
for(int i=1;i<vec.size();i++)
vec[i]+=vec[i-1];
long long mx = vec[0], res = vec[0];
for(int i=1;i<vec.size();i++)
{
if(mx < vec[i])
mx = vec[i];
else
res = min(res,min(vec[i],vec[i]-mx));
}
return res;
}
long long GetMinPref(vector<long long> vec)
{
long long res = 0;
for(int i=1;i<vec.size();i++)
vec[i] += vec[i-1];
for(int i=0;i<vec.size();i++)
res = min(res,vec[i]);
return res;
}
long long GetMinSuf(vector<long long> vec)
{
long long res = 0;
for(int i=(int)vec.size()-1;i>=0;i--)
vec[i] += vec[i+1];
for(int i=0;i<vec.size();i++)
res = min(res,vec[i]);
return res;
}
int main()
{
if(MyNodeId() == 0)
{
long long n = GetN();
int m = NumberOfNodes();
for(int i=1;i<m;i++)
{
PutLL(i,((n*((long long)i-1LL))/((long long)m-1LL)));
PutLL(i,((n*(long long)i)/((long long)m-1LL)));
Send(i);
}
vector<long long> vecsum,vecsolve,minpref,minsuf;
for(int i=1;i<m;i++)
{
Receive(i);
long long su,so,mp,ms;
GetLL(su);
GetLL(so);
GetLL(mp);
GetLL(ms);
vecsum.push_back(su);
vecsolve.push_back(so);
minpref.push_back(mp);
minsuf.push_back(ms);
}
long long res = vecsolve[0], tot = 0;
m = vecsum.size();
forn(i,m)
tot += vecsum[i];
forn(i,m)
res = min(res,vecsolve[0]);
forn(j,m)
forn(i,j)
{
long long aux = minpref[j]+minsuf[i];
for(int t=i+1;t<j;t++)
aux += vecsolve[t];
res = min(res,aux);
}
cout << tot-res << endl;
}
else
{
Receive(0);
long long mn = GetLL(0);
long long mx = GetLL(0);
vector<long long> vec;
for(int i=mn;i<mx;i++)
vec.push_back(GetTaste(i));
PutLL(0,sum(vec));
PutLL(0,solve(vec));
PutLL(0,GetMinPref(vec));
PutLL(0,GetMinSuf(vec));
Send(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/CA%2BE_-jR14Kz51W_zP3aT0T2AbNQhExBmc15%2BjxM4bBAPKV-9uw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.