#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n;
vector <int> ans;
vector <vector <int> > graph;
bool table[300][300];
vector <int> L;
vector <int> R;
vector <int> dir;
int K;
void init(int k, std::vector<int> r)
{
K=k;
n=r.size();
ans=vector <int> (n);
if(n<=300)
{
graph.resize(n);
for(int i=0;i<n;i++)
{
int loc;
int last=-1;
for(int j=n-k;j<n;j++)
{
if(r[j]==0)
{
last=j;
}
}
for(int j=0;j<n;j++)
{
if(r[j]==0)
{
if(last==-1 || (last<j && last+k<=j) || (last>j && j+n-k>=last) || j==last)
{
loc=j;
break;
}
last=j;
}
}
r[loc]=n*4;
for(int j=(loc-k+1+n)%n;j!=loc;j=(j+1)%n)
{
r[j]--;
if(r[j]<=n)
{
graph[j].pb(loc);
}
}
for(int j=(loc+k-1)%n;j!=loc;j=(j-1+n)%n)
{
if(r[j]<=n)
{
graph[j].pb(loc);
}
}
/*for(int j=0;j<n;j++)
{
printf("%d ",r[j]);
}
printf("\n");*/
}
/*for(int i=0;i<n;i++)
{
printf("%d: ",i);
for(int j=0;j<graph[i].size();j++)
{
printf("%d ",graph[i][j]);
}
printf("\n");
}*/
for(int j=0;j<n;j++)
{
vector <bool> v(n,0);
stack <int> st;
st.push(j);
while(st.size())
{
int node=st.top();
st.pop();
v[node]=1;
for(int k=0;k<graph[node].size();k++)
{
if(v[graph[node][k]]==0)
{
st.push(graph[node][k]);
v[graph[node][k]]=1;
}
}
}
for(int k=0;k<n;k++)
{
if(v[k])
{
table[j][k]=1;
}
}
}
}
else if(k!=2)
{
for(int i=0;i<n;i++)
{
int loc;
int last=-1;
for(int j=n-k;j<n;j++)
{
if(r[j]==0)
{
last=j;
}
}
for(int j=0;j<n;j++)
{
if(r[j]==0)
{
if(last==-1 || (last<j && last+k<=j) || (last>j && j+n-k>=last) || j==last)
{
loc=j;
break;
}
last=j;
}
}
r[loc]=n*4;
ans[loc]=i;
for(int j=(loc-k+1+n)%n;j!=loc;j=(j+1)%n)
{
r[j]--;
}
/*for(int j=0;j<n;j++)
{
printf("%d ",r[j]);
}
printf("\n");*/
}
}
else
{
L=R=dir=vector <int> (n);
for(int i=0;i<n;i++)
{
L[i]=i;
R[i]=(i+1)%n;
if(r[i]==0)
{
dir[i]=1;
}
else
{
dir[i]=0;
}
}
for(int i=0;i<n;i++)
{
if(r[i]==r[(i+1)%n])
{
L[(i+1)%n]=L[i];
}
}
for(int i=0;i<n;i++)
{
if(r[i]==r[(i+1)%n])
{
L[(i+1)%n]=L[i];
}
}
for(int i=n-1;i>=0;i--)
{
if(r[i]==r[(i-1+n)%n])
{
R[(i-1+n)%n]=R[i];
}
}
for(int i=n-1;i>=0;i--)
{
if(r[i]==r[(i-1+n)%n])
{
R[(i-1+n)%n]=R[i];
}
}
/*for(int i=0;i<n;i++)
{
printf("%d ",L[i]);
}
printf("\n");
for(int j=0;j<n;j++)
{
printf("%d ",R[j]);
}
printf("\n");*/
}
return;
}
int compare_plants(int x, int y)
{
if(n<=300)
{
if(table[x][y])
{
return -1;
}
if(table[y][x])
{
return 1;
}
return 0;
}
if(K!=2)
{
if(ans[x]<ans[y])
{
return 1;
}
return -1;
}
if(x<y && (y<=R[x] || R[x]<=x))
{
if(dir[x])
{
return 1;
}
return -1;
}
if(x<y && L[(x-1+n)%n]>x && L[(x-1+n)%n]<=y)
{
if(dir[(x-1+n)%n])
{
return -1;
}
return 1;
}
if(x>y)
{
swap(x,y);
}
if(x<y && (y<=R[x] || R[x]<=x))
{
if(dir[x])
{
return -1;
}
return 1;
}
if(x<y && L[(x-1+n)%n]>x && L[(x-1+n)%n]<=y)
{
if(dir[(x-1+n)%n])
{
return 1;
}
return -1;
}
return 0;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(int k=0;k<graph[node].size();k++)
| ~^~~~~~~~~~~~~~~~~~~
plants.cpp:165:9: warning: 'loc' may be used uninitialized in this function [-Wmaybe-uninitialized]
165 | r[loc]=n*4;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
48 ms |
3044 KB |
Output is correct |
7 |
Correct |
58 ms |
3512 KB |
Output is correct |
8 |
Correct |
78 ms |
7272 KB |
Output is correct |
9 |
Correct |
81 ms |
7272 KB |
Output is correct |
10 |
Correct |
76 ms |
7284 KB |
Output is correct |
11 |
Correct |
89 ms |
7272 KB |
Output is correct |
12 |
Correct |
74 ms |
7276 KB |
Output is correct |
13 |
Correct |
90 ms |
7288 KB |
Output is correct |
14 |
Correct |
73 ms |
7284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
340 KB |
Output is correct |
7 |
Correct |
197 ms |
3092 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
340 KB |
Output is correct |
10 |
Correct |
187 ms |
3112 KB |
Output is correct |
11 |
Correct |
146 ms |
3088 KB |
Output is correct |
12 |
Correct |
144 ms |
3220 KB |
Output is correct |
13 |
Correct |
224 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
340 KB |
Output is correct |
7 |
Correct |
197 ms |
3092 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
340 KB |
Output is correct |
10 |
Correct |
187 ms |
3112 KB |
Output is correct |
11 |
Correct |
146 ms |
3088 KB |
Output is correct |
12 |
Correct |
144 ms |
3220 KB |
Output is correct |
13 |
Correct |
224 ms |
3148 KB |
Output is correct |
14 |
Correct |
1588 ms |
3264 KB |
Output is correct |
15 |
Execution timed out |
4064 ms |
4940 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
50 ms |
3052 KB |
Output is correct |
4 |
Execution timed out |
4070 ms |
4968 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
280 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
11 ms |
1028 KB |
Output is correct |
8 |
Correct |
19 ms |
1256 KB |
Output is correct |
9 |
Correct |
13 ms |
1108 KB |
Output is correct |
10 |
Correct |
17 ms |
1236 KB |
Output is correct |
11 |
Correct |
11 ms |
968 KB |
Output is correct |
12 |
Correct |
14 ms |
980 KB |
Output is correct |
13 |
Correct |
28 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
48 ms |
3044 KB |
Output is correct |
7 |
Correct |
58 ms |
3512 KB |
Output is correct |
8 |
Correct |
78 ms |
7272 KB |
Output is correct |
9 |
Correct |
81 ms |
7272 KB |
Output is correct |
10 |
Correct |
76 ms |
7284 KB |
Output is correct |
11 |
Correct |
89 ms |
7272 KB |
Output is correct |
12 |
Correct |
74 ms |
7276 KB |
Output is correct |
13 |
Correct |
90 ms |
7288 KB |
Output is correct |
14 |
Correct |
73 ms |
7284 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
8 ms |
340 KB |
Output is correct |
21 |
Correct |
197 ms |
3092 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
7 ms |
340 KB |
Output is correct |
24 |
Correct |
187 ms |
3112 KB |
Output is correct |
25 |
Correct |
146 ms |
3088 KB |
Output is correct |
26 |
Correct |
144 ms |
3220 KB |
Output is correct |
27 |
Correct |
224 ms |
3148 KB |
Output is correct |
28 |
Correct |
1588 ms |
3264 KB |
Output is correct |
29 |
Execution timed out |
4064 ms |
4940 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |