Submission #1035817

# Submission time Handle Problem Language Result Execution time Memory
1035817 2024-07-26T16:24:07 Z mindiyak Wiring (IOI17_wiring) C++14
7 / 100
128 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();
	vvi dp(m,vi(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] + abs(r[0]-b[i]);
	}

	vi min_dist(n,INT_MAX);

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

	// 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 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 576 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 121 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 Correct 0 ms 348 KB Output is correct
3 Runtime error 128 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 Runtime error 114 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 576 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Runtime error 121 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -