Would you please explain what is wrong with the following solution for Problem
RPS (2016 Distributed Round 1)? I got wrong answer for it.
Thanks.
----------------------------------------
#include "message.h"
#include "rps.h"
#include<map>
#include<set>
#include<string>
#include<vector>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std;
pair<long long,char> s[(1<<17)];
pair<long long,char> res[(1<<7)];
void solve(long long ch){
long long p = 1;
long long next = 2;
while(ch!=1){
for (long long i=0;i<ch;i+=next){
char c1 = s[i].second,c2 = s[i+p].second;
if (c1 == 'P'){
if (c2 == 'S')
s[i] = s[i+p];
}
else if (c1 == 'S'){
if (c2 == 'R')
s[i] = s[i+p];
}
else if (c1 == 'R'){
if (c2 == 'P')
s[i] = s[i+p];
}
}
p = p*2;
next = next*2;
ch/=2;
}
}
int main(){
long long N = NumberOfNodes();
long long id = MyNodeId();
long long n = GetN();
long long n2 = 1;
for (long long i=0;i<n;i++) n2*=2;
long long k = 3; // k = 6 for large
while(2*k > n) k--;
N = 1;
for (long long i=0;i<k;i++) N*=2;
long long ch = n2/N/N;
long long step = N*ch;
if (id>N) return 0;
if (id!=N){
long long st = id*ch;
for (long long i=0;i<N;i++){
for (long long j=0;j<ch;j++){
s[j].first = j;
s[j].second = GetFavoriteMove(st+j);
}
solve(ch);
PutChar(N,s[0].second);
PutLL(N,s[0].first+st);
Send(N);
st += step;
}
}
else{
for (long long i=0;i<N;i++){
for (long long j=0;j<N;j++){
Receive(j);
s[j].second = GetChar(j);
s[j].first = GetLL(j);
}
solve(N);
res[i] = s[0];
}
for (long long i=0;i<N;i++){
s[i] = res[i];
}
solve(N);
cout << s[0].first << endl;
}
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/85b4a345-dd6c-47da-9bc6-a74b7ea61892%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.