Submission #1035843

# Submission time Handle Problem Language Result Execution time Memory
1035843 2024-07-26T16:43:42 Z mindiyak Wiring (IOI17_wiring) C++14
0 / 100
126 ms 262144 KB
#include "wiring.h"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#include <limits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
// #define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;

long long min_total_length(vi r, vi b) {
	int n = r.size(), m = b.size();
	vvl dp(m,vl(n,INT_MAX));
	ll ans = 0;

	dp[0][0] = abs(r[0]-b[0]);

	FOR(i,1,m){
		dp[i][0] = dp[i-1][0] + ll(abs(r[0]-b[i]));
	}

	vl min_dist(n,INT_MAX);

	int b_pos = 0;

	FOR(i,0,n){
		min_dist[i] = min(min_dist[i],ll(abs(r[i]-b[b_pos])));

		if(b[b_pos] < r[i]){
			b_pos++;
			i--;
		}
	}

	// FOR(i,0,n)cout << min_dist[i] << " ";
	// cout << endl;

	FOR(i,1,n){
		dp[0][i] = dp[0][i-1]+min_dist[i];
		FOR(j,1,m){
			dp[j][i] = min(dp[j][i],dp[j][i-1] + min_dist[i]);
			dp[j][i] = min(dp[j][i],dp[j-1][i] + abs(r[i]-b[j]));
			dp[j][i] = min(dp[j][i],dp[j-1][i-1] + abs(r[i]-b[j]));
		}
	}

	// cout << endl;
	// FOR(i,0,m){
	// 	FOR(j,0,n){
	// 		cout << dp[i][j] << " ";
	// 	}cout << endl;
	// }

	return dp[m-1][n-1];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(vi, vi)':
wiring.cpp:46:5: warning: unused variable 'ans' [-Wunused-variable]
   46 |  ll ans = 0;
      |     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '20523'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 126 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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: '1158'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 116 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '20523'
2 Halted 0 ms 0 KB -