Submission #108616

#TimeUsernameProblemLanguageResultExecution timeMemory
108616abilWiring (IOI17_wiring)C++14
7 / 100
1073 ms14840 KiB
#include <bits/stdc++.h> #include "wiring.h" #define mk make_pair #define sc second #define fr first #define pb push_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) #define Scan(a) scanf ("%I64d", &a) #define scan(a) scanf ("%d", &a) using namespace std; const long long INF = (int)1e18 + 7; const int N = (int)1e5 + 12; const int mod = 1000000007; int dp[1111][1111] , red[N], blue[N]; long long min_total_length(std::vector<int > r, std::vector<int > b){ int n = r.size(), m = b.size(); for(int i = 1;i <= n; i++){ red[i] = r[i - 1]; } for(int i = 1;i <= m; i++){ blue[i] = b[i - 1]; } if(red[n] < blue[1]){ long long ans = 0; if(n >= m){ for(int i = 1;i <= m; i++){ ans += abs(blue[i] - red[n - i + 1]); } int i = m; while((n - i)){ ans += abs(blue[1] - red[n - i]); i++; } return ans; } else{ for(int i = 1;i <= n; i++){ ans += abs(blue[i] - red[n - i + 1]); } int i = n + 1; while((m - n)){ ans += abs(blue[i] - red[n]); i++; } return ans; } } else{ memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0][0] = 0; for(int i = 1;i <= n; i++){ for(int j = 1;j <= m; j++){ dp[i][j] = min({dp[i - 1][j - 1],dp[i - 1][j],dp[i][j - 1]}) + abs(red[i] - blue[j]); } } return dp[n][m]; } }
#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...