Submission #359467

# Submission time Handle Problem Language Result Execution time Memory
359467 2021-01-27T04:00:26 Z beksultan04 Comparing Plants (IOI20_plants) C++14
0 / 100
44 ms 47340 KB
#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,vis[1000001];
vector <int> f[1000001],g[1000001];
int find_f(int x){
    if (vis[x] != -1)ret vis[x];
    if (f[x].empty())ret vis[x] = x;
    ret vis[x] = 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;
    for (i=0;i<n;++i){
        which[i] = -1;
        vis[i]=-1;
        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] == -1 && which[i] == -1){
            int x = find_f(i);
            whs++;
            dfs(x);
        }
    }
	ret;
}

int compare_plants(int x, int y) {
    if (which[x] != which[y])ret 0;
    if (cost[x] > cost[y])ret 1;
	ret -1;
}
# 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 32 ms 47340 KB Output is correct
4 Incorrect 36 ms 47340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 47340 KB Output is correct
2 Correct 34 ms 47340 KB Output is correct
3 Incorrect 37 ms 47340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 47340 KB Output is correct
2 Correct 34 ms 47340 KB Output is correct
3 Incorrect 37 ms 47340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 47340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 47340 KB Output is correct
2 Correct 41 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 44 ms 47340 KB Output is correct
2 Correct 39 ms 47340 KB Output is correct
3 Incorrect 35 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 Correct 32 ms 47340 KB Output is correct
4 Incorrect 36 ms 47340 KB Output isn't correct
5 Halted 0 ms 0 KB -