# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068569 | edogawa_something | Wiring (IOI17_wiring) | C++17 | 239 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll inf=1e18;
ll ans,dp[100100][35][35],n,m;
vector<pii>v;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
n=r.size(),m=b.size();
for(int i=0;i<n;i++) {
v.pb({r[i],0});
}
for(int i=0;i<m;i++) {
v.pb({b[i],1});
}
sort(all(v));
dp[0][0][0]=0;
for(int j=0;j<=20;j++)
for(int k=0;k<=20;k++)
dp[0][j][k]=inf;
dp[0][0][0]=0;
for(int i=1;i<=v.size();i++) {
for(int j=0;j<=14;j++) {
for(int k=0;k<=14;k++) {
if(v[i-1].S==1) {
dp[i][j][k]=inf;
for(int c=j;c>=1;c--) {
dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-c][k]-v[i-1].F*c);
}
for(int c=1;c<=14;c++)
dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k+c]+v[i-1].F*c);
}
else {
dp[i][j][k]=inf;
for(int c=k;c>=1;c--) {
dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k-c]-v[i-1].F*c);
}
for(int c=1;c<=14;c++)
dp[i][j][k]=min(dp[i][j][k],dp[i-1][j+c][k]+v[i-1].F*c);
}
}
}
}
return dp[v.size()][0][0];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |