이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef vector < int > vi ;
#define lb lower_bound
#include "wiring.h"
ll Solve1 ( vi a , vi b ) {
ll cost = 0 ;
for ( int i = 0 ; i < a .size () ; i ++ ) {
cost += abs ( a [i] - b [i] ) ;
}
for ( int i = a .size () ; i < b .size () ; i ++ ) {
ll ret = 1e18 ;
auto it = lb ( a .begin () , a .end () , b [i] ) - a .begin () ;
if ( it != a .size () ) {
ret = min ( ret , (ll) ( abs ( b [i] - a [it] ) ) ) ;
}
it -- ;
if ( it != -1 ) {
ret = min ( ret , (ll) ( abs ( b [i] - a [it] ) ) ) ;
}
cost += ret ;
}
return cost ;
}
ll Solve2 ( vi a , vi b ) {
ll cost = 0 , more = b .size () - a .size () ;
for ( int i = 0 ; i < a .size () ; i ++ ) {
cost += abs ( a [i] - b [i+more] ) ;
}
for ( int i = 0 ; i < more ; i ++ ) {
ll ret = 1e18 ;
auto it = lb ( a .begin () , a .end () , b [i] ) - a .begin () ;
if ( it != a .size () ) {
ret = min ( ret , (ll) ( abs ( b [i] - a [it] ) ) ) ;
}
it -- ;
if ( it != -1 ) {
ret = min ( ret , (ll) ( abs ( b [i] - a [it] ) ) ) ;
}
cost += ret ;
}
return cost ;
}
long long min_total_length ( vi a , vi b ) {
if ( a .size () > b .size () ) swap ( a , b ) ;
return min ( Solve1 ( a , b ) , Solve2 ( a , b ) ) ;
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll Solve1(vi, vi)':
wiring.cpp:9:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for ( int i = 0 ; i < a .size () ; i ++ ) {
| ~~^~~~~~~~~~~~
wiring.cpp:12:38: 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 = a .size () ; i < b .size () ; i ++ ) {
| ~~^~~~~~~~~~~~
wiring.cpp:15:25: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if ( it != a .size () ) {
| ~~~^~~~~~~~~~~~~
wiring.cpp: In function 'll Solve2(vi, vi)':
wiring.cpp:28:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for ( int i = 0 ; i < a .size () ; i ++ ) {
| ~~^~~~~~~~~~~~
wiring.cpp:34:25: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if ( it != a .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... |