이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
vector<int> r , b;
long long dp[N][N];
int n , m;
long long solve(int i,int j){
if(i == n && j == m) return 0;
if(j == m) return 1e18;
if(dp[i][j] != -1) return dp[i][j];
dp[i][j] = min(solve(i+1,j),min(solve(i,j+1),solve(i+1,j+1))) + abs(r[i] - b[j]);
return dp[i][j];
}
long long min_total_length(std::vector<int> R, std::vector<int> B) {
memset(dp,-1,sizeof(dp));
r = R;
b = B;
n = r.size();
m = b.size();
if(n <= 500 && m <= 500) return solve(0,0);
if(r.back() < b[0]){
long long sum = 0 ;
int idx = 0 ;
int idx2 = 0;
for(int i=0;i<min(n,m);i++) sum += abs(r[idx++] - b[idx2++]);
for(int i=idx;i<r.size();i++) sum+= abs(r[i] - b[0]);
for(int i=idx2;i<b.size();i++) sum+= abs(b[i] - r.back());
return sum;
}
return rand();
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=idx;i<r.size();i++) sum+= abs(r[i] - b[0]);
^
wiring.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=idx2;i<b.size();i++) sum+= abs(b[i] - r.back());
^
# | 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... |