// Przykładowe (błędne) rozwiązanie - każdy węzeł wysyła węzłowi o numerze 0
// pierwszą z cen swoich akcji. Węzeł 0 wypisuje sumę tych liczb.
#include "message.h"
#include "skup.h"
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
using namespace std;
int tab[100005];
int nc;
int id;
int non;
const int maks = 1000;
int ile;
int main() {
nc = NumberOfCompanies();
id = MyNodeId();
non = NumberOfNodes();
int log = 1;
while(log < non) log<<=1;
if (non <= 10) log = 10;
for(int i=0; i<100000; i++)
tab[i] = IINF;
if (id == 0)
{
//cout << nc << " " << GetShareCost(0) << endl;
}
for(int i=0; i<nc; i++)
{
int xx = GetShareCost(i);
tab[id*maks+i] = xx;
//cout<<id<<" " << i << " " << xx << endl;
}
while(log--)
{
for(int i=0; i<non; i++)
{
if (i == id || ile >= 1900000)
continue;
for(int j=0; j<non*maks; j++)
{
PutInt(i, tab[j]);
ile++;
}
Send(i);
}
for(int i=0; i<non; i++)
{
if (i == id)
continue;
Receive(i);
for(int j=0; j<non*maks; j++)
{
int xx = GetInt(i);
if (xx != 0 && xx != IINF)
tab[j] = xx;
}
}
}
if (id == 0)
{
// for(int i=0; i<13; i++)
// cout<<tab[i] << " ";
sort(tab, tab + maks*non);
ll ile_miast = 0;
ll res = 0;
for(ll i = 0; tab[i] < IINF; i++)
{
ile_miast++;
// cout<<"A"<<i<<" " << tab[i] << endl;
// res += (i+1) * tab[i];
}
for(ll i = 0; tab[i] < IINF; i++)
{
res += (ile_miast-i) * tab[i];
}
cout<<res;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | // Przykładowe (błędne) rozwiązanie - każdy węzeł wysyła węzłowi o numerze 0 // pierwszą z cen swoich akcji. Węzeł 0 wypisuje sumę tych liczb. #include "message.h" #include "skup.h" #include<bits/stdc++.h> #define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++) #define all(v) (v).begin(), (v).end() #define SZ(v) (int)((v).size()) #define pb push_back #define ft first #define sd second typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long long INF = 4e18L + 1; const int IINF = 2e9 + 1; using namespace std; int tab[100005]; int nc; int id; int non; const int maks = 1000; int ile; int main() { nc = NumberOfCompanies(); id = MyNodeId(); non = NumberOfNodes(); int log = 1; while(log < non) log<<=1; if (non <= 10) log = 10; for(int i=0; i<100000; i++) tab[i] = IINF; if (id == 0) { //cout << nc << " " << GetShareCost(0) << endl; } for(int i=0; i<nc; i++) { int xx = GetShareCost(i); tab[id*maks+i] = xx; //cout<<id<<" " << i << " " << xx << endl; } while(log--) { for(int i=0; i<non; i++) { if (i == id || ile >= 1900000) continue; for(int j=0; j<non*maks; j++) { PutInt(i, tab[j]); ile++; } Send(i); } for(int i=0; i<non; i++) { if (i == id) continue; Receive(i); for(int j=0; j<non*maks; j++) { int xx = GetInt(i); if (xx != 0 && xx != IINF) tab[j] = xx; } } } if (id == 0) { // for(int i=0; i<13; i++) // cout<<tab[i] << " "; sort(tab, tab + maks*non); ll ile_miast = 0; ll res = 0; for(ll i = 0; tab[i] < IINF; i++) { ile_miast++; // cout<<"A"<<i<<" " << tab[i] << endl; // res += (i+1) * tab[i]; } for(ll i = 0; tab[i] < IINF; i++) { res += (ile_miast-i) * tab[i]; } cout<<res; } } |
English