#include "plants.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
vector<int> muchii[200005];
int n,bigger[200005],smaller[200005],lastsmall[200005],lastbig[200005],k,v[200005];
bool use[200005];
ll mars[500005],can[500005];
int dist(int a,int b)
{
return (b-a+n)%n;
}
int myprv(int x)
{
return (x-1+n)%n;
}
void init(int K, std::vector<int> r)
{
n=r.size();
k=K;
for(int i=0;i<n;i++)
{
lastbig[i]=-1;
lastsmall[i]=-1;
}
for(int i=0;i<n;i++)
{
if(r[i]==0)
{
int j=(i-1+n)%n;
while(r[j]==1)
{
lastsmall[j]=i;
j=(j-1+n)%n;
}
}
if(r[i]==1)
{
int j=(i-1+n)%n;
while(r[j]==0)
{
lastbig[j]=i;
j=(j-1+n)%n;
}
}
}
if(k>2)
{
for(int value=1;value<=n;value++)
{
vector<int> vals;
for(int i=0;i<=2*n;i++)
{
mars[i]=0;
can[i]=0;
}
for(int j=0;j<n;j++)
if(!use[j])
{
if(r[j]==k-1)
{
mars[j+1]++;
mars[j+k]--;
}
else
can[j]++;
}
ll valmin=1e16;
for(int j=0;j<2*n;j++)
{
if(j>0)
mars[j]+=mars[j-1];
can[j%n]+=mars[j];
}
for(int j=0;j<n;j++)
valmin=min(valmin,can[j]);
for(int j=0;j<n;j++)
if(can[j]==valmin&&!use[j])
vals.push_back(j);
if(vals.empty())
break;
for(int who:vals)
{
use[who]=1;
v[who]=value;
for(int j=myprv(who),cnt=1;cnt<k;cnt++,j=myprv(j))
r[j]++;
}
}
}
}
int compare_plants(int x, int y)
{
if(k==2)
{
if(lastsmall[x]!=-1&&dist(x,y)+dist(y,lastsmall[x])==dist(x,lastsmall[x]))
return -1;
if(lastbig[x]!=-1&&dist(x,y)+dist(y,lastbig[x])==dist(x,lastbig[x]))
return 1;
if(lastsmall[y]!=-1&&dist(y,x)+dist(x,lastsmall[y])==dist(y,lastsmall[y]))
return 1;
if(lastbig[y]!=-1&&dist(y,x)+dist(x,lastbig[y])==dist(y,lastbig[y]))
return -1;
return 0;
}
if(v[x]<v[y])
return -1;
if(v[x]>v[y])
return 1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8792 KB |
Output is correct |
6 |
Correct |
44 ms |
11304 KB |
Output is correct |
7 |
Correct |
47 ms |
11604 KB |
Output is correct |
8 |
Correct |
66 ms |
12628 KB |
Output is correct |
9 |
Correct |
61 ms |
12564 KB |
Output is correct |
10 |
Correct |
61 ms |
12372 KB |
Output is correct |
11 |
Correct |
62 ms |
12592 KB |
Output is correct |
12 |
Correct |
61 ms |
12564 KB |
Output is correct |
13 |
Correct |
57 ms |
12600 KB |
Output is correct |
14 |
Correct |
59 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
20 ms |
10844 KB |
Output is correct |
7 |
Correct |
480 ms |
13492 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
20 ms |
10840 KB |
Output is correct |
10 |
Correct |
476 ms |
13492 KB |
Output is correct |
11 |
Correct |
421 ms |
13492 KB |
Output is correct |
12 |
Correct |
430 ms |
13736 KB |
Output is correct |
13 |
Correct |
498 ms |
13652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
20 ms |
10844 KB |
Output is correct |
7 |
Correct |
480 ms |
13492 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
20 ms |
10840 KB |
Output is correct |
10 |
Correct |
476 ms |
13492 KB |
Output is correct |
11 |
Correct |
421 ms |
13492 KB |
Output is correct |
12 |
Correct |
430 ms |
13736 KB |
Output is correct |
13 |
Correct |
498 ms |
13652 KB |
Output is correct |
14 |
Execution timed out |
4051 ms |
15452 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
69 ms |
13616 KB |
Output is correct |
4 |
Execution timed out |
4056 ms |
20760 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8792 KB |
Output is correct |
6 |
Correct |
44 ms |
11304 KB |
Output is correct |
7 |
Correct |
47 ms |
11604 KB |
Output is correct |
8 |
Correct |
66 ms |
12628 KB |
Output is correct |
9 |
Correct |
61 ms |
12564 KB |
Output is correct |
10 |
Correct |
61 ms |
12372 KB |
Output is correct |
11 |
Correct |
62 ms |
12592 KB |
Output is correct |
12 |
Correct |
61 ms |
12564 KB |
Output is correct |
13 |
Correct |
57 ms |
12600 KB |
Output is correct |
14 |
Correct |
59 ms |
12368 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
20 ms |
10844 KB |
Output is correct |
21 |
Correct |
480 ms |
13492 KB |
Output is correct |
22 |
Correct |
4 ms |
10588 KB |
Output is correct |
23 |
Correct |
20 ms |
10840 KB |
Output is correct |
24 |
Correct |
476 ms |
13492 KB |
Output is correct |
25 |
Correct |
421 ms |
13492 KB |
Output is correct |
26 |
Correct |
430 ms |
13736 KB |
Output is correct |
27 |
Correct |
498 ms |
13652 KB |
Output is correct |
28 |
Execution timed out |
4051 ms |
15452 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |