Submission #301896

# Submission time Handle Problem Language Result Execution time Memory
301896 2020-09-18T09:20:48 Z VEGAnn Comparing Plants (IOI20_plants) C++14
5 / 100
119 ms 10088 KB
#include "plants.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
const int N = 200100;
vector<int> glob;
int n, pre[N][2], suf[N][2];

int nxt(int x){ return (x + 1) % n;}

int get(int tp, int x) {
    return (pre[x][tp] == x ? x : pre[x][tp] = get(tp, pre[x][tp]));
}

void link(int tp, int fi, int se){
    fi = get(tp, fi);
    se = get(tp, se);

    pre[fi][tp] = se;
}

void init(int k, vector<int> r) {
    assert(k == 2);

    n = sz(r);

    for (int i = 0; i < n; i++){
        pre[i][0] = pre[i][1] = i;
    }

    glob = r;

    for (int i = 0; i < n; i++)
        if (r[i] == 0)
            link(0, i, nxt(i));
        else link(1, i, nxt(i));

    suf[n][0] = suf[n][1] = 0;

    for (int i = n - 1; i >= 0; i--){
        suf[i][0] = suf[i + 1][0];
        suf[i][1] = suf[i + 1][1];

        suf[i][r[i] ^ 1]++;
    }

    return;
}

int compare_plants(int x, int y) {

    if (get(0, x) == get(0, y)){
        if (x > y){
            if (suf[y][0] - suf[x][0] > 0)
                return 1;
            else return -1;
        } else {
            if (suf[x][0] - suf[y][0] > 0)
                return -1;
            else return 1;
        }
    }

    if (get(1, x) == get(1, y)){
        if (x > y){
            if (suf[y][1] - suf[x][1] > 0)
                return -1;
            else return 1;
        } else {
            if (suf[x][1] - suf[y][1] > 0)
                return 1;
            else return -1;
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 71 ms 3196 KB Output is correct
7 Correct 86 ms 3832 KB Output is correct
8 Correct 119 ms 8184 KB Output is correct
9 Correct 114 ms 8184 KB Output is correct
10 Correct 115 ms 8184 KB Output is correct
11 Correct 116 ms 8296 KB Output is correct
12 Correct 113 ms 9064 KB Output is correct
13 Correct 109 ms 9704 KB Output is correct
14 Correct 119 ms 10088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Runtime error 1 ms 512 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Runtime error 1 ms 512 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Runtime error 1 ms 512 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Runtime error 1 ms 512 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Runtime error 1 ms 512 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 71 ms 3196 KB Output is correct
7 Correct 86 ms 3832 KB Output is correct
8 Correct 119 ms 8184 KB Output is correct
9 Correct 114 ms 8184 KB Output is correct
10 Correct 115 ms 8184 KB Output is correct
11 Correct 116 ms 8296 KB Output is correct
12 Correct 113 ms 9064 KB Output is correct
13 Correct 109 ms 9704 KB Output is correct
14 Correct 119 ms 10088 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Runtime error 1 ms 512 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -