Submission #542425

# Submission time Handle Problem Language Result Execution time Memory
542425 2022-03-26T17:00:44 Z two_sides Minerals (JOI19_minerals) C++17
85 / 100
51 ms 4380 KB
#include "minerals.h"
#include <bits/stdc++.h>


namespace {
    using namespace std;

    const int N = 43005;

    int cost[N], best[N], cur = 0;

    void Prepare() {
        cost[1] = 0; best[1] = 1;
        for (int i = 2; i < N; i++) {
            int j = best[i - 1];
            if (cost[i - j - 1] + cost[j + 1] +
            j + 1 < cost[i - j] + cost[j] + j) j++;
            cost[i] = cost[i - j] + cost[j] + j + i;
            best[i] = j;
        }
    }

    void Split(vector<int> x, vector<int> y, bool f) {
        if (x.size() == 1)
            return Answer(x[0], y[0]);
        int n = x.size(), len = best[n];
        vector<int> nx[2], ny[2];
        for (int i = 0; i < len; i++) {
            nx[f ^ 1].push_back(x[i]);
            cur = Query(x[i]);
        }
        for (int i = len; i < n; i++)
            nx[f].push_back(x[i]);
        for (int i = 0; i < n; i++) {
            int nxt = Query(y[i]);
            if (cur != nxt)
                ny[1].push_back(y[i]);
            else ny[0].push_back(y[i]);
            cur = nxt;
        }
        Split(nx[0], ny[0], 0);
        Split(nx[1], ny[1], 1);
    }
}

void Solve(int n) {
    Prepare(); vector<int> x, y;
    for (int i = 1; i <= 2 * n; i++) {
        int nxt = Query(i);
        if (nxt != cur) x.push_back(i);
        else y.push_back(i);
        cur = nxt;
    }
    Split(x, y, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 720 KB Output is correct
2 Correct 3 ms 828 KB Output is correct
3 Correct 5 ms 976 KB Output is correct
4 Correct 8 ms 1232 KB Output is correct
5 Correct 15 ms 1924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
19 Correct 44 ms 4196 KB Output is correct
20 Correct 45 ms 4172 KB Output is correct
21 Correct 39 ms 4148 KB Output is correct
22 Correct 36 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
19 Correct 44 ms 4196 KB Output is correct
20 Correct 45 ms 4172 KB Output is correct
21 Correct 39 ms 4148 KB Output is correct
22 Correct 36 ms 4052 KB Output is correct
23 Correct 48 ms 4116 KB Output is correct
24 Correct 48 ms 4180 KB Output is correct
25 Correct 38 ms 4224 KB Output is correct
26 Correct 48 ms 4056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
19 Correct 44 ms 4196 KB Output is correct
20 Correct 45 ms 4172 KB Output is correct
21 Correct 39 ms 4148 KB Output is correct
22 Correct 36 ms 4052 KB Output is correct
23 Correct 48 ms 4116 KB Output is correct
24 Correct 48 ms 4180 KB Output is correct
25 Correct 38 ms 4224 KB Output is correct
26 Correct 48 ms 4056 KB Output is correct
27 Correct 51 ms 4188 KB Output is correct
28 Correct 45 ms 4324 KB Output is correct
29 Correct 38 ms 4340 KB Output is correct
30 Correct 38 ms 4128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
19 Correct 44 ms 4196 KB Output is correct
20 Correct 45 ms 4172 KB Output is correct
21 Correct 39 ms 4148 KB Output is correct
22 Correct 36 ms 4052 KB Output is correct
23 Correct 48 ms 4116 KB Output is correct
24 Correct 48 ms 4180 KB Output is correct
25 Correct 38 ms 4224 KB Output is correct
26 Correct 48 ms 4056 KB Output is correct
27 Correct 51 ms 4188 KB Output is correct
28 Correct 45 ms 4324 KB Output is correct
29 Correct 38 ms 4340 KB Output is correct
30 Correct 38 ms 4128 KB Output is correct
31 Incorrect 46 ms 4380 KB Wrong Answer [2]
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 564 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 8 ms 1232 KB Output is correct
9 Correct 15 ms 1924 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 14 ms 1528 KB Output is correct
12 Correct 19 ms 1952 KB Output is correct
13 Correct 14 ms 2000 KB Output is correct
14 Correct 16 ms 1920 KB Output is correct
15 Correct 43 ms 4064 KB Output is correct
16 Correct 42 ms 4024 KB Output is correct
17 Correct 35 ms 4044 KB Output is correct
18 Correct 35 ms 3980 KB Output is correct
19 Correct 44 ms 4196 KB Output is correct
20 Correct 45 ms 4172 KB Output is correct
21 Correct 39 ms 4148 KB Output is correct
22 Correct 36 ms 4052 KB Output is correct
23 Correct 48 ms 4116 KB Output is correct
24 Correct 48 ms 4180 KB Output is correct
25 Correct 38 ms 4224 KB Output is correct
26 Correct 48 ms 4056 KB Output is correct
27 Correct 51 ms 4188 KB Output is correct
28 Correct 45 ms 4324 KB Output is correct
29 Correct 38 ms 4340 KB Output is correct
30 Correct 38 ms 4128 KB Output is correct
31 Incorrect 46 ms 4380 KB Wrong Answer [2]
32 Halted 0 ms 0 KB -