Submission #756075

# Submission time Handle Problem Language Result Execution time Memory
756075 2023-06-11T04:22:28 Z PixelCat Rope (JOI17_rope) C++14
45 / 100
2500 ms 3152 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
#define INF (int)(1e18)
using namespace std;
using LL = long long;
using pii = pair<int, int>;

void chmin(int &x, int a) {
    x = min(x, a);
}
void chmax(int &x, int a) {
    x = max(x, a);
}

const int MAXN = 1000010;

int ans[MAXN];

void solve(int n, int m, vector<pii> v2, vector<int> v1) {
    for(auto &i:v2) {
        if(i.F > i.S) swap(i.F, i.S);
    }  // i.F <= i.S
    For(c1, 1, m) For(c2, c1, m) {
        int cost = 0;
        for(auto &i:v2) {
            int a = (i.F != c1) + (i.S != c1);
            int b = (i.F != c2) + (i.S != c2);
            cost += min(a, b);
        }
        for(auto &i:v1) {
            cost += min(i != c1, i != c2);
        }
        chmin(ans[c1], cost);
        chmin(ans[c2], cost);
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // =^-w-^=
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(auto &i:a) cin >> i;

    For(i, 1, m) ans[i] = INF;

    if(n % 2) {
        For(_, 0, 1) {
            vector<pii> v2;
            for(int i = 1; i < n; i += 2) {
                v2.eb(pii(a[i - 1], a[i]));
            }
            solve(n, m, v2, { a.back() });
            reverse(all(a));
        }
    } else {
        vector<pii> v2;
        for(int i = 1; i < n; i += 2) {
            v2.eb(pii(a[i - 1], a[i]));
        }
        solve(n, m, v2, {});

        v2.clear();
        for(int i = 2; i < n; i += 2) {
            v2.eb(pii(a[i - 1], a[i]));
        }
        solve(n, m, v2, { a.front(), a.back() });
    }

    For(i, 1, m) cout << ans[i] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 20 ms 3024 KB Output is correct
28 Correct 10 ms 3024 KB Output is correct
29 Correct 19 ms 3024 KB Output is correct
30 Correct 13 ms 3128 KB Output is correct
31 Correct 20 ms 2996 KB Output is correct
32 Correct 10 ms 3028 KB Output is correct
33 Correct 19 ms 3120 KB Output is correct
34 Correct 11 ms 3120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 20 ms 3024 KB Output is correct
28 Correct 10 ms 3024 KB Output is correct
29 Correct 19 ms 3024 KB Output is correct
30 Correct 13 ms 3128 KB Output is correct
31 Correct 20 ms 2996 KB Output is correct
32 Correct 10 ms 3028 KB Output is correct
33 Correct 19 ms 3120 KB Output is correct
34 Correct 11 ms 3120 KB Output is correct
35 Execution timed out 2548 ms 3152 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 20 ms 3024 KB Output is correct
28 Correct 10 ms 3024 KB Output is correct
29 Correct 19 ms 3024 KB Output is correct
30 Correct 13 ms 3128 KB Output is correct
31 Correct 20 ms 2996 KB Output is correct
32 Correct 10 ms 3028 KB Output is correct
33 Correct 19 ms 3120 KB Output is correct
34 Correct 11 ms 3120 KB Output is correct
35 Execution timed out 2548 ms 3152 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 20 ms 3024 KB Output is correct
28 Correct 10 ms 3024 KB Output is correct
29 Correct 19 ms 3024 KB Output is correct
30 Correct 13 ms 3128 KB Output is correct
31 Correct 20 ms 2996 KB Output is correct
32 Correct 10 ms 3028 KB Output is correct
33 Correct 19 ms 3120 KB Output is correct
34 Correct 11 ms 3120 KB Output is correct
35 Execution timed out 2548 ms 3152 KB Time limit exceeded
36 Halted 0 ms 0 KB -