Submission #1005992

#TimeUsernameProblemLanguageResultExecution timeMemory
1005992thangdz2k7Wiring (IOI17_wiring)C++17
0 / 100
0 ms348 KiB
#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[0] = 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]); } //int main(){ // cout << min_total_length(vector <int> {1, 2, 3, 7}, vector <int> {0, 4, 5, 9, 10}); //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...