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"
#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 (stderr)
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 |
---|
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... |