이 제출은 이전 버전의 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()
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
vector<unordered_map<ll, 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].count(red+changed*2+am*4)) 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) {
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, {});
return dp(0, 0);
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:5:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define fo(i, n) for(ll i = 0; i<(n); i++)
| ^
wiring.cpp:38:5: note: in expansion of macro 'fo'
38 | fo(i, r.size()){
| ^~
wiring.cpp:5:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define fo(i, n) for(ll i = 0; i<(n); i++)
| ^
wiring.cpp:41:5: note: in expansion of macro 'fo'
41 | fo(i, b.size()){
| ^~
# | 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... |