Submission #365410

# Submission time Handle Problem Language Result Execution time Memory
365410 2021-02-11T15:41:32 Z valerikk Comparing Plants (IOI20_plants) C++17
14 / 100
4000 ms 9580 KB
#include <bits/stdc++.h>

using namespace std;

int k, n;
vector<int> r;
vector<int> h;

void build_h() {
    h = vector<int>(n, -1);
    for (int t = n - 1; t >= 0; t--) {
        int pos = -1;
        
        for (int i = n - 1; i >= 0; i--) {
            if (r[i] == 0 && h[i] == -1 && (pos == -1 || (pos - i + n) % n < k))
                pos = i;
        }

        for (int i = n - 1; i >= 0; i--) {
            if (r[i] == 0 && h[i] == -1 && (pos == -1 || (pos - i + n) % n < k))
                pos = i;
        } 
        
        assert(pos != -1);

        h[pos] = t;
        for (int i = 1; i < k; i++) 
            r[(pos - i + n) % n]--;
    }
}

void init(int k_, vector<int> r_) {
    n = r_.size();
    k = k_;
    r = r_;

    build_h();
}

int compare_plants(int x, int y) {
    return h[x] > h[y] ? 1 : -1;
}

#ifndef EVAL
void test() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> r(n);
    for (int i = 0; i < n; i++) 
        cin >> r[i];
    
    init(k, r);
  
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << compare_plants(x, y) << "\n";
    }
}

int main() {
    freopen("D:/cp/oi/ioi/2020/input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    test();

    return 0;
}
#endif

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 492 KB Output is correct
7 Correct 248 ms 5208 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 11 ms 640 KB Output is correct
10 Correct 251 ms 5100 KB Output is correct
11 Correct 292 ms 5100 KB Output is correct
12 Correct 204 ms 5228 KB Output is correct
13 Correct 295 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 10 ms 492 KB Output is correct
7 Correct 248 ms 5208 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 11 ms 640 KB Output is correct
10 Correct 251 ms 5100 KB Output is correct
11 Correct 292 ms 5100 KB Output is correct
12 Correct 204 ms 5228 KB Output is correct
13 Correct 295 ms 5120 KB Output is correct
14 Correct 2078 ms 5664 KB Output is correct
15 Execution timed out 4070 ms 9580 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 78 ms 3180 KB Output is correct
4 Execution timed out 4090 ms 8684 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -