#include "plants.h"
//Bismillahirrahmanirrahim
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int m,b[li],a[li],flag,t,siz[li],say,vis[li],dep[li],kk;
int cev;
string s;
vector<int> v[li],vv;
inline void dfs(int node,int der){
if(vis[node])return;
vis[node]=say;
dep[node]=der;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i];
dfs(go,der+1);
}
}
void init(int k, std::vector<int> r) {
for(int i=0;i<(int)r.size();i++){
if(r[i]==1){
v[(i+1)%(int)r.size()].pb(i);
siz[i]++;
}
}
//~ queue<int>
int n=(int)r.size();
//~ FOR{
//~ if(siz[i]==0){
//~ say++;
//~ dfs(i,0);
//~ }
//~ }
vv=r;
say=0;
kk=k;
for(int i=0;i<(int)vv.size();i++){
int ind=-1,ind1=-1;
for(int j=0;j<(int)vv.size();j++){
if(vis[j])continue;
if(vv[j]==0 && ind==-1)ind=j;
else if(vv[j]==0)ind1=j;
}
while(1){
flag=0;
for(int j=0;j<(int)vv.size();j++){
if(vis[j])continue;
if(((j+kk-1)>=ind && j<ind) || ((j+kk-1)%(int)vv.size()>=ind && j+kk-1>=(int)vv.size())){
if(vv[j]==0){ind=j;flag=1;break;}
}
}
if(!flag)break;
}
for(int j=0;j<(int)vv.size();j++){
if(vis[j])continue;
if(((j+kk-1)>=ind && j<ind) || ((j+kk-1)%(int)vv.size()>=ind && j+kk-1>=(int)vv.size())){
vv[j]--;
}
}
vis[ind]=++say;
continue;
}
}
int compare_plants(int x, int y) {
if(vis[x]<vis[y])return 1;
if(vis[x]>vis[y])return -1;
if(vis[x]==vis[y]){
//~ cout<<x<<" : : "<<y<<" : ;"<<vis[x]<<" : : "<<vis[y]<<endl;
return 0;
}
if(vis[x]!=vis[y])return 0;
if(dep[x]>dep[y])return -1;
return 1;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:64:14: warning: variable 'ind1' set but not used [-Wunused-but-set-variable]
64 | int ind=-1,ind1=-1;
| ^~~~
plants.cpp:53:6: warning: unused variable 'n' [-Wunused-variable]
53 | int n=(int)r.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12032 KB |
Output is correct |
4 |
Incorrect |
8 ms |
12032 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
Output is correct |
2 |
Correct |
9 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12032 KB |
Output is correct |
4 |
Correct |
9 ms |
12032 KB |
Output is correct |
5 |
Correct |
9 ms |
12032 KB |
Output is correct |
6 |
Correct |
18 ms |
12160 KB |
Output is correct |
7 |
Correct |
319 ms |
15096 KB |
Output is correct |
8 |
Correct |
11 ms |
12160 KB |
Output is correct |
9 |
Correct |
18 ms |
12160 KB |
Output is correct |
10 |
Correct |
293 ms |
15100 KB |
Output is correct |
11 |
Correct |
243 ms |
14968 KB |
Output is correct |
12 |
Correct |
176 ms |
15096 KB |
Output is correct |
13 |
Correct |
311 ms |
15224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
Output is correct |
2 |
Correct |
9 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12032 KB |
Output is correct |
4 |
Correct |
9 ms |
12032 KB |
Output is correct |
5 |
Correct |
9 ms |
12032 KB |
Output is correct |
6 |
Correct |
18 ms |
12160 KB |
Output is correct |
7 |
Correct |
319 ms |
15096 KB |
Output is correct |
8 |
Correct |
11 ms |
12160 KB |
Output is correct |
9 |
Correct |
18 ms |
12160 KB |
Output is correct |
10 |
Correct |
293 ms |
15100 KB |
Output is correct |
11 |
Correct |
243 ms |
14968 KB |
Output is correct |
12 |
Correct |
176 ms |
15096 KB |
Output is correct |
13 |
Correct |
311 ms |
15224 KB |
Output is correct |
14 |
Execution timed out |
4070 ms |
14840 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
9 ms |
12032 KB |
Output is correct |
3 |
Correct |
611 ms |
15036 KB |
Output is correct |
4 |
Execution timed out |
4080 ms |
16760 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
Output is correct |
2 |
Correct |
9 ms |
12032 KB |
Output is correct |
3 |
Incorrect |
9 ms |
12032 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
9 ms |
12032 KB |
Output is correct |
3 |
Incorrect |
9 ms |
12032 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12032 KB |
Output is correct |
4 |
Incorrect |
8 ms |
12032 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |