Submission #1035411

# Submission time Handle Problem Language Result Execution time Memory
1035411 2024-07-26T10:30:22 Z Zicrus Comparing Plants (IOI20_plants) C++17
5 / 100
57 ms 10360 KB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
 
typedef long long ll;
 
vector<ll> lnk;
vector<int> a;
 
ll find(ll a) {
    if (lnk[a] != a) lnk[a] = find(lnk[a]);
    return lnk[a];
}
 
void unite(ll a, ll b) {
    a = find(a); b = find(b);
    lnk[b] = a;
}
 
bool same(ll a, ll b) {
    return find(a) == find(b);
}
 
void init(int k, vector<int> r) {
    ll n = r.size();
    lnk = vector<ll>(n);
    for (int i = 0; i < n; i++) lnk[i] = i;
    for (int i = n-1; i >= 0; i--) {
        int o = (i+1) % n;
        if (r[i] == r[o]) unite(i, o);
    }
    a = vector<int>(n);
    for (int i = 0; i < n; i++) a[i] = r[i];
}
 
int compare_plants(int x, int y) {
    ll n = a.size();
 
    ll mul = 1;
    if (find(x) > x || find((x-1+n)%n) >= x) { swap(x, y); mul = -1; }
 
    if (same(x, (y-1+n)%n)) {
         return (a[x] ? -1 : 1) * mul;
    }
    if (same((x-1+n)%n, y)) {
        return (!a[y] ? -1 : 1) * mul;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 36 ms 4036 KB Output is correct
7 Correct 40 ms 5728 KB Output is correct
8 Correct 57 ms 9556 KB Output is correct
9 Correct 54 ms 9548 KB Output is correct
10 Correct 52 ms 9552 KB Output is correct
11 Correct 56 ms 9556 KB Output is correct
12 Correct 52 ms 9796 KB Output is correct
13 Correct 50 ms 10152 KB Output is correct
14 Correct 50 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 36 ms 4036 KB Output is correct
7 Correct 40 ms 5728 KB Output is correct
8 Correct 57 ms 9556 KB Output is correct
9 Correct 54 ms 9548 KB Output is correct
10 Correct 52 ms 9552 KB Output is correct
11 Correct 56 ms 9556 KB Output is correct
12 Correct 52 ms 9796 KB Output is correct
13 Correct 50 ms 10152 KB Output is correct
14 Correct 50 ms 10360 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -