Submission #406730

# Submission time Handle Problem Language Result Execution time Memory
406730 2021-05-18T03:52:48 Z casperwang Wiring (IOI17_wiring) C++14
0 / 100
1 ms 236 KB
#include "wiring.h"
#include <bits/stdc++.h>
#define ll 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]; }

vector<pii> build(vector<int> r, vector<int> 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;
}

ll min_total_length(vector<int> r, vector<int> b) {
	vector<pii> arr = build(r, b);
	vector<ll> dp(arr.size()+1);
	int kL, kR;
	ll inc;
	bool flag = false;
	for (int i = 0; i < arr.size(); i++) {
		if (flag) {
			inc += arr[i].ff;
			ll 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);
			}
		}
		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()];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < arr.size(); i++) {
      |                  ~~^~~~~~~~~~~~
wiring.cpp:41:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   if (i+1 < arr.size() && arr[i].ss != arr[i+1].ss) {
      |       ~~~~^~~~~~~~~~~~
wiring.cpp:42:7: warning: 'kR' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |    kL = kR + 1, kR = i;
      |    ~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 236 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '904', found: '326'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '316', found: '188'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '27', found: '19'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 236 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -