#include "wiring.h"
#include <bits/stdc++.h>
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
ll n,m;
vector<ll> R,B;
map<vector<ll>, ll> cache;
ll dp(ll x, ll y){
if (abs(x-y) > 5) return 1000000000000000;
if (cache.count({x,y})) return cache[{x,y}];
if (x==n && y==m) return 0;
if (x>=n || y >= m) return 1000000000000000;
return cache[{x,y}] = min(dp(x+1,y), min(dp(x,y+1), dp(x+1,y+1))) + abs(R[x] - B[y]);
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
R = r;
B = b;
n = r.size();
m = b.size();
return dp(0,0);
}
Compilation message
wiring.cpp: In function 'll dp(ll, ll)':
wiring.cpp:16:27: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '1000000000000000' to '-1530494976' [-Woverflow]
16 | if (abs(x-y) > 5) return 1000000000000000;
| ^~~~~~~~~~~~~~~~
wiring.cpp:19:29: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '1000000000000000' to '-1530494976' [-Woverflow]
19 | if (x>=n || y >= m) return 1000000000000000;
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '-1530482224' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '904', found: '-1530494684' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '316', found: '-1530494800' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '27', found: '-1530494957' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '-1530482224' |
2 |
Halted |
0 ms |
0 KB |
- |