Submission #1051317

# Submission time Handle Problem Language Result Execution time Memory
1051317 2024-08-10T04:26:47 Z pawned Wiring (IOI17_wiring) C++17
0 / 100
1000 ms 60056 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;

#include "wiring.h"

ll min_total_length(vector<int> r_g, vector<int> b_g) {
	vi r, b;
	for (int x : r_g)
		r.pb(x);
	for (int x : b_g)
		b.pb(x);
	int N = r.size();
	int M = b.size();
	map<ii, ll> dp;
	// dp[i][j]: min cost to connect first i red (exclusive)
	// with first j blue (exclusive)
	dp[{0, 0}] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = max(i - 10, 1); j <= min(i + 10, M); j++) {
			dp[{i, j}] = 1e18;
			if (dp.find({i, j - 1}) != dp.end())
				dp[{i, j}] = min(dp[{i, j}], dp[{i, j - 1}] + abs(r[i - 1] - b[j - 1]));
			if (dp.find({i - 1, j}) != dp.end())
				dp[{i, j}] = min(dp[{i, j}], dp[{i - 1, j}] + abs(r[i - 1] - b[j - 1]));
			if (dp.find({i - 1, j - 1}) != dp.end())
				dp[{i, j}] = min(dp[{i, j}], dp[{i - 1, j - 1}] + abs(r[i - 1] - b[j - 1]));
		}
	}
	return dp[{N, M}];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 2 ms 696 KB 3rd lines differ - on the 1st token, expected: '445668', found: '446967'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '84383', found: '0'
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 Execution timed out 1055 ms 57908 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1090 ms 60056 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 2 ms 696 KB 3rd lines differ - on the 1st token, expected: '445668', found: '446967'
8 Halted 0 ms 0 KB -