This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "plants.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, k;
vector<int>a;
vector<int>cons0, cons1;
bool ent1 = false;
int her(int x, int y) {
if (y < x)y += n;
return y - x;
}
void init(int K, vector<int> r) {
n = r.size();
k = K;
a = r;
if (k == 2) {
ent1 = true;
int cur0 = 0, cur1 = 0;
int f1 = 0, f0 = 0;
cons0.resize(n, 0);
cons1.resize(n, 0);
for (int i = 0; i < 2 * n; i++) {
if (r[i % n] == 1) {
if (cur0 != 0) {
while (f0 != i % n) {
cons0[f0] = cur0;
f0++;
cur0--;
f0 %= n;
}
f1 = i % n;
}
cur1++;
}
else {
if (cur1 != 0) {
while (f1 != i % n) {
cons1[f1] = cur1;
f1++;
cur1--;
f1 %= n;
}
f0 = i % n;
}
cur0++;
}
}
/*for (auto x : cons0) {
cout << x << " ";
}
cout << endl;
for (auto x : cons1) {
cout << x << " ";
}
cout << endl;*/
}
}
int compare_plants(int x, int y) {
if (ent1) {
if (cons0[x] >= her(x, y) || cons1[y] >= her(y, x)) {
return 1;
}
if (cons1[x] >= her(x, y) || cons0[y] >= her(y, x)) {
return -1;
}
return 0;
}
}
/*
4 2 3
1 1 0 0
0 1
0 2
0 3
*/
Compilation message (stderr)
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
80 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |