#include "wiring.h"
#include <bits/stdc++.h>
typedef long long 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;
unordered_map<ll, ll> cache;
ll dp(ll x, ll y){
if (cache.count(x*1000000+y)) return cache[x*1000000+y];
if (x==n && y==m) return 0;
if (x>=n || y >= m) return 1000000000000000;
if (abs(R[x]-B[y]) > 100) return 1000000000000000;
return cache[x*1000000+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.clear();
B.clear();
cache.clear();
for (auto&i : r) R.push_back(i);
for (auto&i : b) B.push_back(i);
n = r.size();
m = b.size();
return dp(0,0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '1000000000000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '84383', found: '1000000000000000' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '1000000000000000' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
15 ms |
5556 KB |
3rd lines differ - on the 1st token, expected: '373710605', found: '1000000000000000' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '1000000000000000' |
2 |
Halted |
0 ms |
0 KB |
- |