Submission #838022

# Submission time Handle Problem Language Result Execution time Memory
838022 2023-08-26T05:14:59 Z Kerim Wiring (IOI17_wiring) C++17
0 / 100
1000 ms 13756 KB
#include "wiring.h"
#include "bits/stdc++.h"
#define ff first 
#define ss second
#define ll long long
using namespace std;
const ll B = 1e16;
ll min_total_length(vector<int> r, vector<int> b) {
	vector<pair<int,int> > v;
	vector<vector<int> > d;
	vector<int> sz; 
	for (auto x: r) v.push_back({x, 0});
	for (auto x: b) v.push_back({x, 1});
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++){
		int j = i;
		vector<int> g{-1};
		while (j < v.size() and v[i].ss == v[j].ss){
			g.push_back(v[j].ff);
			j += 1;
		}
		d.push_back(g);
		sz.push_back(j - i);
		i = j - 1;
	}
	int block_size = 0, n = d.size();
	for (auto x: sz) block_size = max(block_size, x);
	vector<vector<ll> > dp(n, vector<ll>(block_size+1, B));
	dp[0][0] = 0;
	for (int i = 1; i < n; i++){
		dp[i][0] = dp[i-1][sz[i-1]];
		for (int j = 1; j <= sz[i]; j++)
			for (int k = 1; k <= sz[i-1]; k++){
				ll cost = (d[i][1] - d[i-1][sz[i-1]])*1LL*max(j, (sz[i-1] - k + 1));
				for (int h = k; h <= sz[i-1]; h++) cost += d[i-1][sz[i-1]] - d[i-1][h];
				for (int h = 1; h <= j; h++) cost += d[i][h] - d[i][1];
				dp[i][j] = min(dp[i][j], dp[i-1][k-1] + cost);
			}
	}
	return dp[n-1][sz[n-1]];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:15: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]
   15 |  for (int i = 0; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
wiring.cpp:18:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   while (j < v.size() and v[i].ss == v[j].ss){
      |          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 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 212 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Execution timed out 1081 ms 7000 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 50 ms 13756 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 212 KB Output is correct
2 Execution timed out 1078 ms 8148 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -