#include "plants.h"
#ifndef EVAL
#include "grader.cpp"
#endif // EVAL
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
int which[1000001],cost[1000001],whs;
bool vis[1000001];
vector <int> f[1000001],g[1000001];
int find_f(int x){
vis[x] = 1;
if (f[x].empty())ret x;
ret find_f(f[x][0]);
}
void dfs(int x,int cnt=0){
cost[x] = cnt;
which[x] = whs;
if (g[x].empty())ret ;
dfs(g[x][0],cnt+1);
}
void init(int k, vector<int> r) {
int n=r.size(),i,cnt=0,howmany = 0;
for (i=0;i<n;++i){
if (r[i] == 1){
int y = (i+1)%n;
g[i].pb(y);
f[y].pb(i);
}
}
for (i=0;i<n;++i){
if (vis[i] == 0){
int x = find_f(i);
dfs(x);
whs++;
}
}
ret;
}
int compare_plants(int x, int y) {
if (which[x] != which[y])ret 0;
if (cost[x] > cost[y])ret 1;
ret -1;
}
Compilation message
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:44:22: warning: unused variable 'cnt' [-Wunused-variable]
44 | int n=r.size(),i,cnt=0,howmany = 0;
| ^~~
plants.cpp:44:28: warning: unused variable 'howmany' [-Wunused-variable]
44 | int n=r.size(),i,cnt=0,howmany = 0;
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Correct |
33 ms |
47340 KB |
Output is correct |
4 |
Incorrect |
33 ms |
47340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Incorrect |
32 ms |
47340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Incorrect |
32 ms |
47340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
47340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Incorrect |
33 ms |
47340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Incorrect |
33 ms |
47360 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47340 KB |
Output is correct |
2 |
Correct |
32 ms |
47340 KB |
Output is correct |
3 |
Correct |
33 ms |
47340 KB |
Output is correct |
4 |
Incorrect |
33 ms |
47340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |