이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
long long dp[200002];
long long dp1[202][202];
long long inf = 1e15;
long long fun(vector <int> x, vector <int> y){
long long ans = 0;
if(x.size() == 0 || y.size()==0)
return inf;
for(int i = 0 ; i <= x.size() ;i++){
for(int j = 0 ; j <= y.size() ; j++){
dp1[i][j]=inf;
}
}
dp1[0][0]=0;
for(int i = 0 ; i < x.size() ;i++){
for(int j = 0 ; j < y.size() ; j++){
dp1[i+1][j+1] = min(dp1[i][j] , min(dp1[i][j+1] , dp1[i+1][j] ) ) + + abs(x[i] - y[j]);
}
}
return dp1[x.size()][y.size()];
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
vector < pair <int, int> > pr;
sort(r.begin(), r.end());
sort(b.begin(), b.end());
int n = r.size();
int m = b.size();
for(int i = 0 ; i < n; i++){
pr.push_back(make_pair(r[i], 0));
}
for(int i = 0 ; i < m; i++){
pr.push_back(make_pair(b[i], 1));
}
if(r.back() < b[0]){
long long sum = 0;
for(int i = 0 ;i < r.size(); i++)
sum += (r.back() - r[i]);
for(int i = 0 ;i < b.size(); i++)
sum += (b[i] - b[0]);
return sum + max(r.size(), b.size()) * 1ll * (b[0] - r.back());
}
if(n >201 || m > 201){
for(int i = 0 ; i < n + m; i++){
dp[i+1]=inf;
for(int j = i-1 ;j >= 0 && i-j > 14;j-- ){
vector <int> r1, b1;
for(int k = j ; k <= j ;k++){
if(pr[k].second == 0 )
r1.push_back(pr[k].first);
else
b1.push_back(pr[k].first);
}
if(j==0)
dp[i+1] = min(dp[i+1], fun(r1, b1));
else
dp[i+1] = min(dp[i+1], dp[j] + fun(r1, b1));
}
}
return dp[n+m];
}
return fun(r, b);
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int fun(std::vector<int>, std::vector<int>)':
wiring.cpp:12:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i = 0 ; i <= x.size() ;i++){
| ~~^~~~~~~~~~~
wiring.cpp:13:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int j = 0 ; j <= y.size() ; j++){
| ~~^~~~~~~~~~~
wiring.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0 ; i < x.size() ;i++){
| ~~^~~~~~~~~~
wiring.cpp:19:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int j = 0 ; j < y.size() ; j++){
| ~~^~~~~~~~~~
wiring.cpp:9:15: warning: unused variable 'ans' [-Wunused-variable]
9 | long long ans = 0;
| ^~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0 ;i < r.size(); i++)
| ~~^~~~~~~~~~
wiring.cpp:43:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 0 ;i < b.size(); i++)
| ~~^~~~~~~~~~
# | 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... |