Created
May 29, 2016 17:02
-
-
Save kusano/43420cc15588ac238ea706b2eb30eeb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "message.h" | |
#include "winning_move.h" | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <map> | |
using namespace std; | |
long long xor64(long long x) | |
{ | |
x ^= x << 13; | |
x ^= x >> 7; | |
x ^= x << 17; | |
x ^= x << 13; | |
x ^= x >> 7; | |
x ^= x << 17; | |
return x & 0x7fffffffffffffffLL; | |
} | |
int main() { | |
long long N = NumberOfNodes(); | |
long long ID = MyNodeId(); | |
long long n = GetNumPlayers(); | |
long long w = (n+N-1)/N; | |
long long l = ID*w; | |
long long r = min(l+w, n); | |
w = r - l; | |
vector<long long> T(w); | |
for (long long i=l; i<r; i++) | |
T[i-l] = GetSubmission(i); | |
map<long long, int> M; | |
for (long long t: T) | |
M[t]++; | |
for (auto &m: M) | |
{ | |
long long t = xor64(m.first) % N; | |
for (int i=0; i<(int)min(m.second, 2); i++) | |
PutLL(t, m.first); | |
} | |
for (int i=0; i<N; i++) | |
PutLL(i, -1LL), | |
Send(i); | |
T.clear(); | |
for (int i=0; i<N; i++) | |
{ | |
Receive(i); | |
long long t; | |
while ((t=GetLL(i))>=0) | |
T.push_back(t); | |
} | |
sort(T.begin(), T.end()); | |
long long ans = 0LL; | |
for (int i=0; i<(int)T.size() && ans==0LL; i++) | |
{ | |
if ((i==0 || T[i]!=T[i-1]) && | |
(i==(int)T.size()-1 || T[i]!=T[i+1])) | |
ans = T[i]; | |
} | |
PutLL(0, ans); | |
Send(0); | |
if (ID==0) | |
{ | |
long long ans = 0; | |
for (int i=0; i<N; i++) | |
{ | |
Receive(i); | |
long long t = GetLL(i); | |
if (t > 0) | |
{ | |
if (ans==0 || t < ans) | |
ans = t; | |
} | |
} | |
cout<<ans<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment