Submission #406771

# Submission time Handle Problem Language Result Execution time Memory
406771 2021-05-18T04:47:40 Z casperwang Wiring (IOI17_wiring) C++14
0 / 100
1000 ms 7848 KB
#include "wiring.h"
#include <bits/stdc++.h>
#define int long long
#define pb emplace_back
#define All(x) x.begin(), x.end()
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int INF = 1e18;

vector<pii> build(vector<signed> r, vector<signed> b) {
	vector<pii> arr;
	for (int i : r) arr.pb(i, 0);
	for (int i : b) arr.pb(i, 1);
	sort(All(arr));
	return arr;
}

int solve(vector<signed> r, vector<signed> b) {
	vector<pii> arr = build(r, b);
	vector<int> dp(arr.size()+1);
	int kL, kR = -1;
	int inc;
	bool flag = false;
	for (int i = 0; i < arr.size(); i++) {
		if (flag) {
			inc += arr[i].ff;
			int dec = (i - kR) * (- arr[kR].ff);
			dp[i+1] = dp[kR] + inc + dec;
			for (int j = kR-1; j >= kL; j--) {
				if (kR - j + 1 > i - kR)
					dec += arr[kR+1].ff - arr[kR].ff;
				dec += arr[kR].ff - arr[j].ff;
				dp[i+1] = min(dp[i+1], dp[j] + inc + dec);
			}
		} else dp[i+1] = INF;
		if (i+1 < arr.size() && arr[i].ss != arr[i+1].ss) {
			kL = kR + 1, kR = i;
			flag = true;
			inc = 0;
		}
	}
	return dp[arr.size()];
}

int min_total_length(vector<signed> r, vector<signed> b) {
	int ans = solve(r, b);
	return ans;
}

Compilation message

wiring.cpp: In function 'long long int solve(std::vector<int>, std::vector<int>)':
wiring.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for (int i = 0; i < arr.size(); i++) {
      |                  ~~^~~~~~~~~~~~
wiring.cpp:43:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if (i+1 < arr.size() && arr[i].ss != arr[i+1].ss) {
      |       ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Execution timed out 1082 ms 7144 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 52 ms 7844 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1152497305'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 1092 ms 7848 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -