이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define pb push_back
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
vector<vector<ll>> memo;
ll n;
vpl v;
ll dp(ll pos, ll am, ll red = 1, ll changed = 0){
if(am>10) return 1e18;
if(pos == n) return (am?1e18:0);
if(memo[pos][red+changed*2+am*4] != -1) return memo[pos][red+changed*2+am*4];
ll &ans = memo[pos][red+changed*2+am*4];
// deb2(pos, am);
ans = 1e18;
if(changed) ans = dp(pos+1, am, red)+(v[pos+1].F-v[pos].F)*am;
if(am==0) ans = min(dp(pos, am+1, v[pos].S, 1), ans);
else if(v[pos].S == red) ans = min(dp(pos, am+1, red, 1), ans);
else ans = min(dp(pos, am-1, red, 1), ans);
return ans;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
sort(rall(r));
ll i = r.size()-1;
ll j= b.size()-1;
ll ans = 0;
while(i+j){
ans+=b[j]-r[i];
if(i)i--;
if(j)j--;
}
return ans;
// fo(i, r.size()){
// v.pb({r[i], 1});
// }
// fo(i, b.size()){
// v.pb({b[i], 0});
// }
// sort(all(v));
// n = v.size();
// v.pb(v[n-1]);
// memo.assign(n+1, vl(100, -1));
// return dp(0, 0);
}
# | 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... |