//
// main.cpp
// pa_tea
//
// Created by Michał Kowalski on 14/12/2018.
// Copyright © 2018 Michał Kowalski. All rights reserved.
//
#include "message.h"
#include "teatr.h"
#include <stdio.h>
#include <vector>
using namespace std;
int nodeId;
int allNodes;
int N;
vector<int> A;
long long R = 0;
void readInput() {
N = GetN();
for(int i=0;i<N;++i) A.push_back(GetElement(i));
}
long long findConflicts(int start) {
long long C = 0;
int J = start-1;
int mH = A[start];
while( J >= 0) {
C += (mH < A[J]) ? 1 : 0;
--J;
}
return C;
}
long long findSolutions() {
int currentNode = nodeId;
long long R = 0;
while(currentNode < N) {
R += findConflicts(currentNode);
currentNode += allNodes;
}
return R;
}
int main(int argc, const char * argv[]) {
allNodes = NumberOfNodes();
nodeId = MyNodeId();
readInput();
if (nodeId == 0) {
long long RESULT = findSolutions();
for (int i=1;i<allNodes;++i) {
Receive(i);
RESULT += GetLL(i);
}
printf("%lld\n",RESULT);
} else {
long long resultToSend = findSolutions();
PutLL(0, resultToSend);
Send(0);
}
return 0;
}
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 | // // main.cpp // pa_tea // // Created by Michał Kowalski on 14/12/2018. // Copyright © 2018 Michał Kowalski. All rights reserved. // #include "message.h" #include "teatr.h" #include <stdio.h> #include <vector> using namespace std; int nodeId; int allNodes; int N; vector<int> A; long long R = 0; void readInput() { N = GetN(); for(int i=0;i<N;++i) A.push_back(GetElement(i)); } long long findConflicts(int start) { long long C = 0; int J = start-1; int mH = A[start]; while( J >= 0) { C += (mH < A[J]) ? 1 : 0; --J; } return C; } long long findSolutions() { int currentNode = nodeId; long long R = 0; while(currentNode < N) { R += findConflicts(currentNode); currentNode += allNodes; } return R; } int main(int argc, const char * argv[]) { allNodes = NumberOfNodes(); nodeId = MyNodeId(); readInput(); if (nodeId == 0) { long long RESULT = findSolutions(); for (int i=1;i<allNodes;++i) { Receive(i); RESULT += GetLL(i); } printf("%lld\n",RESULT); } else { long long resultToSend = findSolutions(); PutLL(0, resultToSend); Send(0); } return 0; } |
English