Submission #1051985

# Submission time Handle Problem Language Result Execution time Memory
1051985 2024-08-10T10:54:23 Z Unforgettablepl Wiring (IOI17_wiring) C++17
7 / 100
113 ms 262144 KB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX_DIVERGENCE = 1000;
const long long INF = 1e15;

long long min_total_length(vector<int> r, vector<int> b) {
	vector<pair<int,int>> arr;
	for(int&i:b)arr.emplace_back(i,0);
	for(int&i:r)arr.emplace_back(i,1);
	sort(arr.begin(), arr.end());
	int n = arr.size();
	arr.insert(arr.begin(),{false,-1});
	vector DP(n+1,vector(2,vector(MAX_DIVERGENCE+1,INF)));
	DP[0][0][0]=DP[0][1][0]=0;
	for(int i=1;i<=n;i++) {
		auto [idx,mycolour] = arr[i];
		int oppocolour = mycolour^1;
		DP[i][oppocolour][MAX_DIVERGENCE]=INF;
		for(int j=MAX_DIVERGENCE-1;j>=0;j--) {
			DP[i][oppocolour][j]=min(DP[i-1][oppocolour][j+1]+idx,DP[i][oppocolour][j+1]+idx);
		}
		DP[i][mycolour][0]=DP[i][oppocolour][0];
		for(int j=1;j<=MAX_DIVERGENCE;j++) {
			DP[i][mycolour][j]=min(DP[i-1][mycolour][j-1]-idx,DP[i][mycolour][j-1]-idx);
		}
	}
	return DP[n][0][0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 3 ms 6796 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 4 ms 6796 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6756 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Runtime error 108 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Runtime error 113 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Runtime error 105 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 3 ms 6796 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 4 ms 6796 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6756 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Runtime error 108 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -