| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 579812 | definitelynotmee | 전선 연결 (IOI17_wiring) | C++98 | 67 ms | 8288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include"wiring.h"
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const ll INFL = 5e17;
struct smartset{
ll lz = 0;
multiset<ll> s = {INFL};
void insert(ll i){
s.insert(i-lz);
}
void add(ll x){
lz+=x;
}
ll min(){
return *s.begin()+lz;
}
void remove(ll x){
s.erase(s.find(x));
}
};
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n = r.size(), m = b.size();
int p1 = 0, p2 = 0;
vector<ll> lastdp ={0};
ll lastx = -1;
while(p1 < n && p2 < m){
if(r[p1] > b[p2]){
swap(r,b);
swap(p1,p2);
swap(n,m);
}
vector<ll> cur;
while(p1 < n && r[p1] < b[p2]){
cur.push_back(r[p1]);
p1++;
}
vector<ll> dp(cur.size()+1,INFL);
ll discount = cur[0]-lastx;
if(lastx == -1){
dp[0] = 0;
for(int i = 0; i < cur.size(); i++){
dp[0]+=b[p2]-cur[i];
}
} else [[likely]] {
smartset s;
int sz = lastdp.size();
ll mindp = INFL;
ll connect = 0;
for(ll i : lastdp)
s.insert(i);
for(int i = 0; i < cur.size(); i++){
connect+=b[p2]-cur[i];
}
for(int i = 0; i < cur.size(); i++){
mindp = min(mindp,s.min());
dp[i] = connect + mindp;
if(sz-i-1 >= 0)
s.remove(lastdp[sz-i-1]);
connect-=b[p2]-cur[i];
connect+=cur[i]-lastx;
s.add(-discount);
}
mindp = min(mindp,s.min());
dp.back() = connect+mindp;
}
lastx = cur.back();
swap(dp,lastdp);
}
int ct = 0;
ll discount = b[p2]-lastx;
ll cost = 0, resp = INFL;
while(p2 < m){
cost+=b[p2]-lastx;
ct++;
p2++;
}
int sz = lastdp.size();
for(int i = 0; i < sz; i++){
resp = min(resp, cost+lastdp[i]-min(ct,sz-i-1)*discount);
}
return resp;
}컴파일 시 표준 에러 (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... | ||||
