Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-09 Thread Fergany willy biloa
  Envoyé de mon smartphone BlackBerry 10.De: Xiongqi ZHANGEnvoyé: jeudi 8 juin 2017 18:06À: Google Code JamRépondre à: google-code@googlegroups.comObjet: Re: [gcj] about problem query of death Distributed GCJ 2017I didn't know the rule you mentioned either and I couldn't find the reference.AFAIK, you should be able to send two consecutive message between the same pair of nodes.Can you cite your reference?Reynaldo Gil-Pons 于2017年6月8日周四 上午7:04写道:I received from another post a reference for a rule in distributed code jam environment I didn't know, that you can't send two consecutive messages between the same pair of nodes. So I changed that, and began debugging again, and finally got AC. I had a little bug, not counting the digits corresponding to the 0 node. At least my probability reasoning was OK, I'm sharing the code to reamin as proof of concept :) (only 20 checks per position were enough, 30 got TLE after correcting bug)


#include 
#include 
#include 
#include "query_of_death.h"
#include 
#include 
using namespace std;
// Receive(int)
// GetLL(int)
// Send(int)
// PutLL(int)
// MyNodeId()
// NumberOfNodes()
typedef long long i64;

const int MOD = 1 << 20;
int main() {
    int n = GetLength();
    int OFFSET = 1e6;
    int node = MyNodeId();
    int nnodes = NumberOfNodes();
    //assert(nnodes == 100);
    int bad = -1;
    int sum = 0;
    //srand(1);
    for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){

      int cur = GetValue(i);

      for(int j = 0; j < 20; j++){
          int tmp = GetValue(i);
          if(tmp != cur){
            bad = i;
            break;
            }
        }
        if(bad != -1){
          break;
          }
        sum += cur;

  }
  if(node == 0){

      if(bad != -1){
        int ans = 0;
        for(int i = 1; i < nnodes; i++){
            Receive(i);
            int cur = GetLL(i);
            assert(cur >= 0);
            ans += cur;
          }


        PutLL(1, -bad - 1);
        Send(1);
        Receive(1);
        GetLL(1);
        PutLL(1, ans);
        Send(1);


        }
        else{
          int ans = sum;
          int badi = -1;
          for(int i = 1; i < nnodes; i++){
            Receive(i);
            int resp = GetLL(i);
            if(resp < 0){
              badi = i;
              bad = -(resp + 1);
            }else
              ans += resp;
          }
          assert(bad >= 0);
          assert(badi > 0);
          for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET); i++){
            if(i == bad)continue;
            //assert(i >= 0 and i < n);
            int ii = GetValue(i);
            ans += ii;
            assert(GetValue(i) == ii);
            }
            //assert(bad >= 0 and bad < n);
            ans += GetValue(bad);
            cout << ans << endl;






          PutLL(1, 0);
          Send(1);
        }

    }
    else{
      if(bad == -1){
        PutLL(0, sum);
        Send(0);
      }
      else{
        PutLL(0, -bad - 1);
        Send(0);
        }


      }
  if(node == 1){
      Receive(0);
      int resp = GetLL(0);
      if(resp < 0){
          PutLL(0, -1);
          Send(0);
          bad = -(resp + 1);
          Receive(0);
          int ans = GetLL(0);
          for(int i = 0; i < min(n, OFFSET); i++){
            if(i == bad)continue;
            int ii = GetValue(i);
            ans += ii;
            assert(GetValue(i) == ii);
            }
            //assert(bad >= 0 and bad < n);
            ans += GetValue(bad);
            cout << ans << endl;
        }

    }


  return 0;
}






On Monday, June 5, 2017 at 9:56:49 AM UTC-4, Reynaldo Gil-Pons wrote:
> OK, I didn't think anyone would like to review code... This is the overall explanation: first each node tries to sum values on an interval, and send answer to node 0. When a node notices it's wrong, sends a different info to node 0. Then node 0 solves the rest of the problem. If node 0 was the one that failed, then node 1 solves the rest of the problem...
>
>
> code (hope not too messy):
>
>
> #include 
> #include 
> #include 
> #include "query_of_death.h"
> #include 
> #include 
> using namespace std;
> // Receive(int)
> // GetLL(int)
> // Send(int)
> // PutLL(int)
> // MyNodeId()
> // NumberOfNodes()
> typedef long long i64;
>
> const int MOD = 1 << 20;
> int main() {
>     int n = GetLength();
>  

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-08 Thread Xiongqi ZHANG
It feels quite awkward to have such requirement.
I guess it is due to some restriction on how Message library was
implemented.
I think these requirement should be relaxed if possible, even though we can
always pack those messages into one.


'Pablo Heiber' via Google Code Jam 于2017年6月8日周四
上午11:17写道:

> Hi,
>
> Here is the reference:
>
> "Also, you cannot send a message from node A to node B if there is already
> a message from A to B that has not been read."
>
> Last sentence of "Your submission results" section, from the quickstart
> guide: https://code.google.com/codejam/resources/quickstart-guide
>
> FWIW, the behavior of doing so is unspecified, so it might work if you
> test it, especially with small messages, but it's not guaranteed to work
> correctly every time (it may make the program crash, get a memory limit
> exceeded or a rule violation). In an actual contest, you can try doing it
> at your own risk.
>
> Best,
> Pablo
>
>
> On Thu, Jun 8, 2017 at 11:06 AM, Xiongqi ZHANG 
> wrote:
> >
> > I didn't know the rule you mentioned either and I couldn't find the
> reference.
> > AFAIK, you should be able to send two consecutive message between the
> same pair of nodes.
> >
> > Can you cite your reference?
> >
> >
> >
> > Reynaldo Gil-Pons 于2017年6月8日周四 上午7:04写道:
> >>
> >> I received from another post a reference for a rule in distributed code
> jam environment I didn't know, that you can't send two consecutive messages
> between the same pair of nodes. So I changed that, and began debugging
> again, and finally got AC. I had a little bug, not counting the digits
> corresponding to the 0 node. At least my probability reasoning was OK, I'm
> sharing the code to reamin as proof of concept :) (only 20 checks per
> position were enough, 30 got TLE after correcting bug)
> >>
> >>
> >> #include 
> >> #include 
> >> #include 
> >> #include "query_of_death.h"
> >> #include 
> >> #include 
> >> using namespace std;
> >> // Receive(int)
> >> // GetLL(int)
> >> // Send(int)
> >> // PutLL(int)
> >> // MyNodeId()
> >> // NumberOfNodes()
> >> typedef long long i64;
> >>
> >> const int MOD = 1 << 20;
> >> int main() {
> >> int n = GetLength();
> >> int OFFSET = 1e6;
> >> int node = MyNodeId();
> >> int nnodes = NumberOfNodes();
> >> //assert(nnodes == 100);
> >> int bad = -1;
> >> int sum = 0;
> >> //srand(1);
> >> for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){
> >>
> >>   int cur = GetValue(i);
> >>
> >>   for(int j = 0; j < 20; j++){
> >>   int tmp = GetValue(i);
> >>   if(tmp != cur){
> >> bad = i;
> >> break;
> >> }
> >> }
> >> if(bad != -1){
> >>   break;
> >>   }
> >> sum += cur;
> >>
> >>   }
> >>   if(node == 0){
> >>
> >>   if(bad != -1){
> >> int ans = 0;
> >> for(int i = 1; i < nnodes; i++){
> >> Receive(i);
> >> int cur = GetLL(i);
> >> assert(cur >= 0);
> >> ans += cur;
> >>   }
> >>
> >>
> >> PutLL(1, -bad - 1);
> >> Send(1);
> >> Receive(1);
> >> GetLL(1);
> >> PutLL(1, ans);
> >> Send(1);
> >>
> >>
> >> }
> >> else{
> >>   int ans = sum;
> >>   int badi = -1;
> >>   for(int i = 1; i < nnodes; i++){
> >> Receive(i);
> >> int resp = GetLL(i);
> >> if(resp < 0){
> >>   badi = i;
> >>   bad = -(resp + 1);
> >> }else
> >>   ans += resp;
> >>   }
> >>   assert(bad >= 0);
> >>   assert(badi > 0);
> >>   for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET);
> i++){
> >> if(i == bad)continue;
> >> //assert(i >= 0 and i < n);
> >> int ii = GetValue(i);
> >> ans += ii;
> >> assert(GetValue(i) == ii);
> >> }
> >> //assert(bad >= 0 and bad < n);
> >> ans += GetValue(bad);
> >> cout << ans << endl;
> >>
> >>
> >>
> >>
> >>
> >>
> >>   PutLL(1, 0);
> >>   Send(1);
> >> }
> >>
> >> }
> >> else{
> >>   if(bad == -1){
> >> PutLL(0, sum);
> >> Send(0);
> >>   }
> >>   else{
> >> PutLL(0, -bad - 1);
> >> Send(0);
> >> }
> >>
> >>
> >>   }
> >>   if(node == 1){
> >>   Receive(0);
> >>   int resp = GetLL(0);
> >>   if(resp < 0){
> >>   PutLL(0, -1);
> >>   Send(0);
> >>   bad = -(resp + 1);
> >>   Receive(0);
> >>   int ans = GetLL(0);
> >>   for(int i = 0; i < min(n, OFFSET); i++){
> >> if(i == bad)continue;
> >> int ii = GetValue(i);
> >> ans += ii;
> >> assert(GetValue(i) == ii);
> >> }
> >> 

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-08 Thread 'Pablo Heiber' via Google Code Jam
Hi,

Here is the reference:

"Also, you cannot send a message from node A to node B if there is already
a message from A to B that has not been read."

Last sentence of "Your submission results" section, from the quickstart
guide: https://code.google.com/codejam/resources/quickstart-guide

FWIW, the behavior of doing so is unspecified, so it might work if you test
it, especially with small messages, but it's not guaranteed to work
correctly every time (it may make the program crash, get a memory limit
exceeded or a rule violation). In an actual contest, you can try doing it
at your own risk.

Best,
Pablo

On Thu, Jun 8, 2017 at 11:06 AM, Xiongqi ZHANG 
wrote:
>
> I didn't know the rule you mentioned either and I couldn't find the
reference.
> AFAIK, you should be able to send two consecutive message between the
same pair of nodes.
>
> Can you cite your reference?
>
>
>
> Reynaldo Gil-Pons 于2017年6月8日周四 上午7:04写道:
>>
>> I received from another post a reference for a rule in distributed code
jam environment I didn't know, that you can't send two consecutive messages
between the same pair of nodes. So I changed that, and began debugging
again, and finally got AC. I had a little bug, not counting the digits
corresponding to the 0 node. At least my probability reasoning was OK, I'm
sharing the code to reamin as proof of concept :) (only 20 checks per
position were enough, 30 got TLE after correcting bug)
>>
>>
>> #include 
>> #include 
>> #include 
>> #include "query_of_death.h"
>> #include 
>> #include 
>> using namespace std;
>> // Receive(int)
>> // GetLL(int)
>> // Send(int)
>> // PutLL(int)
>> // MyNodeId()
>> // NumberOfNodes()
>> typedef long long i64;
>>
>> const int MOD = 1 << 20;
>> int main() {
>> int n = GetLength();
>> int OFFSET = 1e6;
>> int node = MyNodeId();
>> int nnodes = NumberOfNodes();
>> //assert(nnodes == 100);
>> int bad = -1;
>> int sum = 0;
>> //srand(1);
>> for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){
>>
>>   int cur = GetValue(i);
>>
>>   for(int j = 0; j < 20; j++){
>>   int tmp = GetValue(i);
>>   if(tmp != cur){
>> bad = i;
>> break;
>> }
>> }
>> if(bad != -1){
>>   break;
>>   }
>> sum += cur;
>>
>>   }
>>   if(node == 0){
>>
>>   if(bad != -1){
>> int ans = 0;
>> for(int i = 1; i < nnodes; i++){
>> Receive(i);
>> int cur = GetLL(i);
>> assert(cur >= 0);
>> ans += cur;
>>   }
>>
>>
>> PutLL(1, -bad - 1);
>> Send(1);
>> Receive(1);
>> GetLL(1);
>> PutLL(1, ans);
>> Send(1);
>>
>>
>> }
>> else{
>>   int ans = sum;
>>   int badi = -1;
>>   for(int i = 1; i < nnodes; i++){
>> Receive(i);
>> int resp = GetLL(i);
>> if(resp < 0){
>>   badi = i;
>>   bad = -(resp + 1);
>> }else
>>   ans += resp;
>>   }
>>   assert(bad >= 0);
>>   assert(badi > 0);
>>   for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET);
i++){
>> if(i == bad)continue;
>> //assert(i >= 0 and i < n);
>> int ii = GetValue(i);
>> ans += ii;
>> assert(GetValue(i) == ii);
>> }
>> //assert(bad >= 0 and bad < n);
>> ans += GetValue(bad);
>> cout << ans << endl;
>>
>>
>>
>>
>>
>>
>>   PutLL(1, 0);
>>   Send(1);
>> }
>>
>> }
>> else{
>>   if(bad == -1){
>> PutLL(0, sum);
>> Send(0);
>>   }
>>   else{
>> PutLL(0, -bad - 1);
>> Send(0);
>> }
>>
>>
>>   }
>>   if(node == 1){
>>   Receive(0);
>>   int resp = GetLL(0);
>>   if(resp < 0){
>>   PutLL(0, -1);
>>   Send(0);
>>   bad = -(resp + 1);
>>   Receive(0);
>>   int ans = GetLL(0);
>>   for(int i = 0; i < min(n, OFFSET); i++){
>> if(i == bad)continue;
>> int ii = GetValue(i);
>> ans += ii;
>> assert(GetValue(i) == ii);
>> }
>> //assert(bad >= 0 and bad < n);
>> ans += GetValue(bad);
>> cout << ans << endl;
>> }
>>
>> }
>>
>>
>>   return 0;
>> }
>>
>>
>>
>>
>>
>>
>> On Monday, June 5, 2017 at 9:56:49 AM UTC-4, Reynaldo Gil-Pons wrote:
>> > OK, I didn't think anyone would like to review code... This is the
overall explanation: first each node tries to sum values on an interval,
and send answer to node 0. When a node notices it's wrong, sends a
different info to node 0. Then node 0 solves the rest of the problem. If
node 0 was the one that failed, then node 1 solves the rest of the
problem...
>> >
>> >
>> > code (hope not too messy):
>> >
>> >
>> > 

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-08 Thread Xiongqi ZHANG
I didn't know the rule you mentioned either and I couldn't find the
reference.
AFAIK, you should be able to send two consecutive message between the same
pair of nodes.

Can you cite your reference?



Reynaldo Gil-Pons 于2017年6月8日周四 上午7:04写道:

> I received from another post a reference for a rule in distributed code
> jam environment I didn't know, that you can't send two consecutive messages
> between the same pair of nodes. So I changed that, and began debugging
> again, and finally got AC. I had a little bug, not counting the digits
> corresponding to the 0 node. At least my probability reasoning was OK, I'm
> sharing the code to reamin as proof of concept :) (only 20 checks per
> position were enough, 30 got TLE after correcting bug)
>
>
> #include 
> #include 
> #include 
> #include "query_of_death.h"
> #include 
> #include 
> using namespace std;
> // Receive(int)
> // GetLL(int)
> // Send(int)
> // PutLL(int)
> // MyNodeId()
> // NumberOfNodes()
> typedef long long i64;
>
> const int MOD = 1 << 20;
> int main() {
> int n = GetLength();
> int OFFSET = 1e6;
> int node = MyNodeId();
> int nnodes = NumberOfNodes();
> //assert(nnodes == 100);
> int bad = -1;
> int sum = 0;
> //srand(1);
> for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){
>
>   int cur = GetValue(i);
>
>   for(int j = 0; j < 20; j++){
>   int tmp = GetValue(i);
>   if(tmp != cur){
> bad = i;
> break;
> }
> }
> if(bad != -1){
>   break;
>   }
> sum += cur;
>
>   }
>   if(node == 0){
>
>   if(bad != -1){
> int ans = 0;
> for(int i = 1; i < nnodes; i++){
> Receive(i);
> int cur = GetLL(i);
> assert(cur >= 0);
> ans += cur;
>   }
>
>
> PutLL(1, -bad - 1);
> Send(1);
> Receive(1);
> GetLL(1);
> PutLL(1, ans);
> Send(1);
>
>
> }
> else{
>   int ans = sum;
>   int badi = -1;
>   for(int i = 1; i < nnodes; i++){
> Receive(i);
> int resp = GetLL(i);
> if(resp < 0){
>   badi = i;
>   bad = -(resp + 1);
> }else
>   ans += resp;
>   }
>   assert(bad >= 0);
>   assert(badi > 0);
>   for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET); i++){
> if(i == bad)continue;
> //assert(i >= 0 and i < n);
> int ii = GetValue(i);
> ans += ii;
> assert(GetValue(i) == ii);
> }
> //assert(bad >= 0 and bad < n);
> ans += GetValue(bad);
> cout << ans << endl;
>
>
>
>
>
>
>   PutLL(1, 0);
>   Send(1);
> }
>
> }
> else{
>   if(bad == -1){
> PutLL(0, sum);
> Send(0);
>   }
>   else{
> PutLL(0, -bad - 1);
> Send(0);
> }
>
>
>   }
>   if(node == 1){
>   Receive(0);
>   int resp = GetLL(0);
>   if(resp < 0){
>   PutLL(0, -1);
>   Send(0);
>   bad = -(resp + 1);
>   Receive(0);
>   int ans = GetLL(0);
>   for(int i = 0; i < min(n, OFFSET); i++){
> if(i == bad)continue;
> int ii = GetValue(i);
> ans += ii;
> assert(GetValue(i) == ii);
> }
> //assert(bad >= 0 and bad < n);
> ans += GetValue(bad);
> cout << ans << endl;
> }
>
> }
>
>
>   return 0;
> }
>
>
>
>
>
>
> On Monday, June 5, 2017 at 9:56:49 AM UTC-4, Reynaldo Gil-Pons wrote:
> > OK, I didn't think anyone would like to review code... This is the
> overall explanation: first each node tries to sum values on an interval,
> and send answer to node 0. When a node notices it's wrong, sends a
> different info to node 0. Then node 0 solves the rest of the problem. If
> node 0 was the one that failed, then node 1 solves the rest of the
> problem...
> >
> >
> > code (hope not too messy):
> >
> >
> > #include 
> > #include 
> > #include 
> > #include "query_of_death.h"
> > #include 
> > #include 
> > using namespace std;
> > // Receive(int)
> > // GetLL(int)
> > // Send(int)
> > // PutLL(int)
> > // MyNodeId()
> > // NumberOfNodes()
> > typedef long long i64;
> >
> > const int MOD = 1 << 20;
> > int main() {
> > int n = GetLength();
> > int OFFSET = 1e6;
> > int node = MyNodeId();
> > int nnodes = NumberOfNodes();
> > assert(nnodes == 100);
> > int bad = -1;
> > int sum = 0;
> > srand(1);
> > for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){
> >
> >   int cur = GetValue(i);
> >
> >   for(int j = 0; j < 33; j++){
> >   int tmp = GetValue(i);
> >   if(tmp != cur){
> > bad = i;
> > break;
> > }
> > }
> >   

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-08 Thread Reynaldo Gil-Pons
I received from another post a reference for a rule in distributed code jam 
environment I didn't know, that you can't send two consecutive messages between 
the same pair of nodes. So I changed that, and began debugging again, and 
finally got AC. I had a little bug, not counting the digits corresponding to 
the 0 node. At least my probability reasoning was OK, I'm sharing the code to 
reamin as proof of concept :) (only 20 checks per position were enough, 30 got 
TLE after correcting bug)


#include 
#include 
#include 
#include "query_of_death.h"
#include 
#include 
using namespace std;
// Receive(int)
// GetLL(int)
// Send(int)
// PutLL(int)
// MyNodeId()
// NumberOfNodes()
typedef long long i64;

const int MOD = 1 << 20;
int main() {
int n = GetLength();
int OFFSET = 1e6;
int node = MyNodeId();
int nnodes = NumberOfNodes();
//assert(nnodes == 100);
int bad = -1;
int sum = 0;
//srand(1);
for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){

  int cur = GetValue(i);
  
  for(int j = 0; j < 20; j++){
  int tmp = GetValue(i);
  if(tmp != cur){
bad = i;
break;
}
}
if(bad != -1){
  break;
  }
sum += cur;

  }
  if(node == 0){
  
  if(bad != -1){
int ans = 0;
for(int i = 1; i < nnodes; i++){
Receive(i);
int cur = GetLL(i);
assert(cur >= 0);
ans += cur;
  }


PutLL(1, -bad - 1);
Send(1);
Receive(1);
GetLL(1);
PutLL(1, ans);
Send(1);


}
else{
  int ans = sum;
  int badi = -1;
  for(int i = 1; i < nnodes; i++){
Receive(i);
int resp = GetLL(i);
if(resp < 0){
  badi = i;
  bad = -(resp + 1);
}else
  ans += resp;
  }
  assert(bad >= 0);
  assert(badi > 0);
  for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET); i++){
if(i == bad)continue;
//assert(i >= 0 and i < n);
int ii = GetValue(i);
ans += ii;
assert(GetValue(i) == ii);
}
//assert(bad >= 0 and bad < n);
ans += GetValue(bad);
cout << ans << endl;

  

  
  
  
  PutLL(1, 0);
  Send(1);
}

}
else{
  if(bad == -1){
PutLL(0, sum);
Send(0);
  }
  else{
PutLL(0, -bad - 1);
Send(0);
}
  
  
  }
  if(node == 1){
  Receive(0);
  int resp = GetLL(0);
  if(resp < 0){
  PutLL(0, -1);
  Send(0);
  bad = -(resp + 1);
  Receive(0);
  int ans = GetLL(0);
  for(int i = 0; i < min(n, OFFSET); i++){
if(i == bad)continue;
int ii = GetValue(i);
ans += ii;
assert(GetValue(i) == ii);
}
//assert(bad >= 0 and bad < n);
ans += GetValue(bad);
cout << ans << endl;
}

}
  
  
  return 0;
}






On Monday, June 5, 2017 at 9:56:49 AM UTC-4, Reynaldo Gil-Pons wrote:
> OK, I didn't think anyone would like to review code... This is the overall 
> explanation: first each node tries to sum values on an interval, and send 
> answer to node 0. When a node notices it's wrong, sends a different info to 
> node 0. Then node 0 solves the rest of the problem. If node 0 was the one 
> that failed, then node 1 solves the rest of the problem...
> 
> 
> code (hope not too messy):
> 
> 
> #include 
> #include 
> #include 
> #include "query_of_death.h"
> #include 
> #include 
> using namespace std;
> // Receive(int)
> // GetLL(int)
> // Send(int)
> // PutLL(int)
> // MyNodeId()
> // NumberOfNodes()
> typedef long long i64;
> 
> const int MOD = 1 << 20;
> int main() {
> int n = GetLength();
> int OFFSET = 1e6;
> int node = MyNodeId();
> int nnodes = NumberOfNodes();
> assert(nnodes == 100);
> int bad = -1;
> int sum = 0;
> srand(1);
> for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){
> 
>   int cur = GetValue(i);
>   
>   for(int j = 0; j < 33; j++){
>   int tmp = GetValue(i);
>   if(tmp != cur){
> bad = i;
> break;
> }
> }
> if(bad != -1){
>   break;
>   }
> sum += cur;
> 
>   }
>   if(node == 0){
>   
>   if(bad != -1){
> int ans = 0;
> for(int i = 1; i < nnodes; i++){
> Receive(i);
> int cur = GetLL(i);
> assert(cur >= 0);
> ans += cur;
>   }
> 
> 
> PutLL(1, -bad - 1);
> Send(1);
> PutLL(1, ans);
> Send(1);
> 
>   

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-05 Thread Reynaldo Gil-Pons
OK, I didn't think anyone would like to review code... This is the overall 
explanation: first each node tries to sum values on an interval, and send 
answer to node 0. When a node notices it's wrong, sends a different info to 
node 0. Then node 0 solves the rest of the problem. If node 0 was the one that 
failed, then node 1 solves the rest of the problem...


code (hope not too messy):


#include 
#include 
#include 
#include "query_of_death.h"
#include 
#include 
using namespace std;
// Receive(int)
// GetLL(int)
// Send(int)
// PutLL(int)
// MyNodeId()
// NumberOfNodes()
typedef long long i64;

const int MOD = 1 << 20;
int main() {
int n = GetLength();
int OFFSET = 1e6;
int node = MyNodeId();
int nnodes = NumberOfNodes();
assert(nnodes == 100);
int bad = -1;
int sum = 0;
srand(1);
for(int i = OFFSET * node ; i < min(n, OFFSET * (node + 1)) ; i++){

  int cur = GetValue(i);
  
  for(int j = 0; j < 33; j++){
  int tmp = GetValue(i);
  if(tmp != cur){
bad = i;
break;
}
}
if(bad != -1){
  break;
  }
sum += cur;

  }
  if(node == 0){
  
  if(bad != -1){
int ans = 0;
for(int i = 1; i < nnodes; i++){
Receive(i);
int cur = GetLL(i);
assert(cur >= 0);
ans += cur;
  }


PutLL(1, -bad - 1);
Send(1);
PutLL(1, ans);
Send(1);


}
else{
  int ans = 0;
  int badi = -1;
  for(int i = 1; i < nnodes; i++){
Receive(i);
int resp = GetLL(i);
if(resp < 0){
  badi = i;
  bad = -(resp + 1);
}else
  ans += resp;
  }
  assert(bad >= 0);
  assert(badi > 0);
  for(int i = badi * OFFSET; i < min(n, (badi + 1) * OFFSET); i++){
if(i == bad)continue;
//assert(i >= 0 and i < n);
int ii = GetValue(i);
ans += ii;
assert(GetValue(i) == ii);
}
//assert(bad >= 0 and bad < n);
ans += GetValue(bad);
cout << ans << endl;

  

  
  
  
  PutLL(1, 0);
  Send(1);
}

}
else{
  if(bad == -1){
PutLL(0, sum);
Send(0);
  }
  else{
PutLL(0, -bad - 1);
Send(0);
}
  
  
  }
  if(node == 1){
  Receive(0);
  int resp = GetLL(0);
  if(resp < 0){
  bad = -(resp + 1);
  Receive(0);
  int ans = GetLL(0);
  for(int i = 0; i < min(n, OFFSET); i++){
if(i == bad)continue;
int ii = GetValue(i);
ans += ii;
assert(GetValue(i) == ii);
}
//assert(bad >= 0 and bad < n);
ans += GetValue(bad);
cout << ans << endl;
}

}
  
  
  return 0;
}


On Monday, June 5, 2017 at 9:48:24 AM UTC-4, Luke Pebody wrote:
> If you are getting WA you have probably made a logical error somewhere. You 
> might have to post your code to know where.
> 
> 
> On 5 Jun 2017 2:35 p.m., "Reynaldo Gil-Pons"  wrote:
> There are 100 computers, 1 microsecond = 1e-6 seconds, so time for reading 
> each number 30 times is: 10 ^ 8 * (0.2 * 10^ -6) / 100 * 30 = 6 seconds, so a 
> little bit above, but I have tested and it passes the time limit, although 
> giving WA, as if the probability reasoning were incorrect...
> 
> 
> 
> 
> On Monday, June 5, 2017 at 12:59:48 AM UTC-4, Xiongqi ZHANG wrote:
> 
> > 10^8 * 0.2 microsecond = 20 seconds while Time Limit is 2 second.
> 
> >
> 
> >
> 
> > Reynaldo Gil-Pons 于2017年6月4日周日 下午7:39写道:
> 
> 
> > 0.2 millisecons to read a single bit? They say 0.2 microseconds. I get WA 
> > when doing what I explained, in 1.7 seconds...
> 
> >
> 
> >
> 
> >
> 
> > On Friday, June 2, 2017 at 12:09:47 PM UTC-4, Luke Pebody wrote:
> 
> >
> 
> > > I would think it can't work on the large case because it takes 0.2 
> > > milliseconds to read a single bit once and therefore 20 seconds to read 
> > > all 100M bits once and 10 minutes to read them 30 times.
> 
> >
> 
> > >
> 
> >
> 
> > >
> 
> >
> 
> > > On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:
> 
> >
> 
> > > In the analisis they explain a solution for the Small case, and point out 
> > > it cannot work for the Large one. When I calculate the probabilities of 
> > > getting WA using 30 checks for each position, and assuming 100 
> > > testcases (cant be more than this right?) I get less than 1 / 1000. But I 
> > > still get WA. I calculate an upper bound on the probability of failure as 
> > > 1 - (1 - 1 / (2 ** 30)) ** number_test_cases. Is there anything wrong?
> 
> >
> 
> > >
> 
> >
> 
> > >
> 
> >
> 
> > >
> 
> >
> 
> > > --
> 
> >

Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-05 Thread Luke Pebody
If you are getting WA you have probably made a logical error somewhere. You
might have to post your code to know where.

On 5 Jun 2017 2:35 p.m., "Reynaldo Gil-Pons"  wrote:

There are 100 computers, 1 microsecond = 1e-6 seconds, so time for reading
each number 30 times is: 10 ^ 8 * (0.2 * 10^ -6) / 100 * 30 = 6 seconds, so
a little bit above, but I have tested and it passes the time limit,
although giving WA, as if the probability reasoning were incorrect...

On Monday, June 5, 2017 at 12:59:48 AM UTC-4, Xiongqi ZHANG wrote:
> 10^8 * 0.2 microsecond = 20 seconds while Time Limit is 2 second.
>
>
> Reynaldo Gil-Pons 于2017年6月4日周日 下午7:39写道:
> 0.2 millisecons to read a single bit? They say 0.2 microseconds. I get WA
when doing what I explained, in 1.7 seconds...
>
>
>
> On Friday, June 2, 2017 at 12:09:47 PM UTC-4, Luke Pebody wrote:
>
> > I would think it can't work on the large case because it takes 0.2
milliseconds to read a single bit once and therefore 20 seconds to read all
100M bits once and 10 minutes to read them 30 times.
>
> >
>
> >
>
> > On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:
>
> > In the analisis they explain a solution for the Small case, and point
out it cannot work for the Large one. When I calculate the probabilities of
getting WA using 30 checks for each position, and assuming 100
testcases (cant be more than this right?) I get less than 1 / 1000. But I
still get WA. I calculate an upper bound on the probability of failure as 1
- (1 - 1 / (2 ** 30)) ** number_test_cases. Is there anything wrong?
>
> >
>
> >
>
> >
>
> > --
>
> >
>
> > 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 google-code...@googlegroups.com.
>
> >
>
> > To post to this group, send email to googl...@googlegroups.com.
>
> >
>
> > To view this discussion on the web visit https://groups.google.com/d/
msgid/google-code/11b46b16-82c3-4824-b319-626b05cf9e76%40googlegroups.com.
>
> >
>
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> 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 google-code...@googlegroups.com.
>
> To post to this group, send email to googl...@googlegroups.com.
>
> To view this discussion on the web visit https://groups.google.com/d/
msgid/google-code/b8d61e73-ddb2-4fdf-bb32-7c61929055a7%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/google-code/cded6fcb-f302-42b2-98db-510d42d43980%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAECKw-Meq4LZR-F1arc7Jbnvp_-pC%2B8DFtzNCtwK6RQBHna58A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-05 Thread Reynaldo Gil-Pons
There are 100 computers, 1 microsecond = 1e-6 seconds, so time for reading each 
number 30 times is: 10 ^ 8 * (0.2 * 10^ -6) / 100 * 30 = 6 seconds, so a little 
bit above, but I have tested and it passes the time limit, although giving WA, 
as if the probability reasoning were incorrect... 

On Monday, June 5, 2017 at 12:59:48 AM UTC-4, Xiongqi ZHANG wrote:
> 10^8 * 0.2 microsecond = 20 seconds while Time Limit is 2 second.
> 
> 
> Reynaldo Gil-Pons 于2017年6月4日周日 下午7:39写道:
> 0.2 millisecons to read a single bit? They say 0.2 microseconds. I get WA 
> when doing what I explained, in 1.7 seconds...
> 
> 
> 
> On Friday, June 2, 2017 at 12:09:47 PM UTC-4, Luke Pebody wrote:
> 
> > I would think it can't work on the large case because it takes 0.2 
> > milliseconds to read a single bit once and therefore 20 seconds to read all 
> > 100M bits once and 10 minutes to read them 30 times.
> 
> >
> 
> >
> 
> > On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:
> 
> > In the analisis they explain a solution for the Small case, and point out 
> > it cannot work for the Large one. When I calculate the probabilities of 
> > getting WA using 30 checks for each position, and assuming 100 
> > testcases (cant be more than this right?) I get less than 1 / 1000. But I 
> > still get WA. I calculate an upper bound on the probability of failure as 1 
> > - (1 - 1 / (2 ** 30)) ** number_test_cases. Is there anything wrong?
> 
> >
> 
> >
> 
> >
> 
> > --
> 
> >
> 
> > 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 google-code...@googlegroups.com.
> 
> >
> 
> > To post to this group, send email to googl...@googlegroups.com.
> 
> >
> 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/google-code/11b46b16-82c3-4824-b319-626b05cf9e76%40googlegroups.com.
> 
> >
> 
> > For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> --
> 
> 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 google-code...@googlegroups.com.
> 
> To post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/b8d61e73-ddb2-4fdf-bb32-7c61929055a7%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/cded6fcb-f302-42b2-98db-510d42d43980%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-04 Thread Xiongqi ZHANG
10^8 * 0.2 microsecond = 20 seconds while Time Limit is 2 second.

Reynaldo Gil-Pons 于2017年6月4日周日 下午7:39写道:

> 0.2 millisecons to read a single bit? They say 0.2 microseconds. I get WA
> when doing what I explained, in 1.7 seconds...
>
> On Friday, June 2, 2017 at 12:09:47 PM UTC-4, Luke Pebody wrote:
> > I would think it can't work on the large case because it takes 0.2
> milliseconds to read a single bit once and therefore 20 seconds to read all
> 100M bits once and 10 minutes to read them 30 times.
> >
> >
> > On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:
> > In the analisis they explain a solution for the Small case, and point
> out it cannot work for the Large one. When I calculate the probabilities of
> getting WA using 30 checks for each position, and assuming 100
> testcases (cant be more than this right?) I get less than 1 / 1000. But I
> still get WA. I calculate an upper bound on the probability of failure as 1
> - (1 - 1 / (2 ** 30)) ** number_test_cases. Is there anything wrong?
> >
> >
> >
> > --
> >
> > 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 google-code...@googlegroups.com.
> >
> > To post to this group, send email to googl...@googlegroups.com.
> >
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/11b46b16-82c3-4824-b319-626b05cf9e76%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/b8d61e73-ddb2-4fdf-bb32-7c61929055a7%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAGDEU-LfVCbRqRWqKd66OT%2B47S3My7Km-sTQAZ6UosugcP9T9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-04 Thread Reynaldo Gil-Pons
0.2 millisecons to read a single bit? They say 0.2 microseconds. I get WA when 
doing what I explained, in 1.7 seconds...

On Friday, June 2, 2017 at 12:09:47 PM UTC-4, Luke Pebody wrote:
> I would think it can't work on the large case because it takes 0.2 
> milliseconds to read a single bit once and therefore 20 seconds to read all 
> 100M bits once and 10 minutes to read them 30 times.
> 
> 
> On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:
> In the analisis they explain a solution for the Small case, and point out it 
> cannot work for the Large one. When I calculate the probabilities of getting 
> WA using 30 checks for each position, and assuming 100 testcases (cant be 
> more than this right?) I get less than 1 / 1000. But I still get WA. I 
> calculate an upper bound on the probability of failure as 1 - (1 - 1 / (2 ** 
> 30)) ** number_test_cases. Is there anything wrong?
> 
> 
> 
> --
> 
> 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 google-code...@googlegroups.com.
> 
> To post to this group, send email to googl...@googlegroups.com.
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/11b46b16-82c3-4824-b319-626b05cf9e76%40googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/b8d61e73-ddb2-4fdf-bb32-7c61929055a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gcj] about problem query of death Distributed GCJ 2017

2017-06-02 Thread Luke Pebody
I would think it can't work on the large case because it takes 0.2
milliseconds to read a single bit once and therefore 20 seconds to read all
100M bits once and 10 minutes to read them 30 times.

On 2 Jun 2017 4:56 p.m., "Reynaldo Gil-Pons"  wrote:

> In the analisis they explain a solution for the Small case, and point out
> it cannot work for the Large one. When I calculate the probabilities of
> getting WA using 30 checks for each position, and assuming 100
> testcases (cant be more than this right?) I get less than 1 / 1000. But I
> still get WA. I calculate an upper bound on the probability of failure as 1
> - (1 - 1 / (2 ** 30)) ** number_test_cases. Is there anything wrong?
>
> --
> 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 google-code+unsubscr...@googlegroups.com.
> To post to this group, send email to google-code@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-code/11b46b16-82c3-4824-b319-626b05cf9e76%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAECKw-PK61s%2BX0nwAABJP0SifyZ5s%2BoYtRMv%2B%2BfhkawVfA-jkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.