Submission #1005984

# Submission time Handle Problem Language Result Execution time Memory
1005984 2024-06-23T09:57:40 Z thangdz2k7 Wiring (IOI17_wiring) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

const long long inf = 1e18;

long long dp[2][2], cost[2];
int l[2], n[2];
vector <int> p[2];

#define pos(k) p[k][l[k]]

void minself(long long &a, long long b){
    a = min(a, b);
}

long long min_total_length(vector <int> r, vector <int> b){
    n[0] = r.size();
    n[1] = b.size();

    for (int a : r) p[0].push_back(a);
    for (int a : b) p[1].push_back(a);

    l[0] = 0;
    l[1] = 0;
    int last = -1;
    for (int i = 0; i < n[0] + n[1]; ++ i){
        int cur = 0;
        if (l[0] == n[0] || (l[1] < n[1] && p[1][l[1]] < p[0][l[0]])) cur = 1;
        cost[0] = inf;
        cost[1] = inf;
        if (l[cur ^ 1] < n[cur ^ 1]) cost[1] = pos(cur ^ 1) - pos(cur);
        if (l[cur ^ 1] > 0) cost[1] = pos(cur) - p[cur ^ 1][l[cur ^ 1] - 1];

        int state = i & 1;
        for (int j : {0, 1}) dp[state][j] = inf;
        if (!i) {
            for (int j : {0, 1}) dp[state][j] = cost[j];
            continue;
        }

        if (cur == last) for (int j : {0, 1}) for (int jlast : {0, 1}) minself(dp[state][j | jlast], dp[state ^ 1][jlast] + cost[j]);
        else {
            dp[state][0] = min(dp[state ^ 1][1], dp[state ^ 1][0] + cost[0]);
            dp[state][1] = min(dp[state ^ 1][0], dp[state ^ 1][1]) + cost[1];
        }

        ++ l[cur];
        last = cur;
    }

    return min(dp[last][0], dp[last][1]);
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '25859', found: '38600'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '904', found: '860'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '316', found: '299'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '40'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '25859', found: '38600'
2 Halted 0 ms 0 KB -