Submission #98883

# Submission time Handle Problem Language Result Execution time Memory
98883 2019-02-27T05:07:48 Z square1001 Wiring (IOI17_wiring) C++14
7 / 100
1000 ms 11864 KB
#include "wiring.h"
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 61;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
	int n = r.size() + b.size();
	vector<pair<int, int> > v;
	for(int i : r) v.push_back(make_pair(i, 0));
	for(int i : b) v.push_back(make_pair(i, 1));
	sort(v.begin(), v.end());
	vector<long long> dp(2 * n + 1, inf);
	dp[n] = 0;
	for(pair<int, int> i : v) {
		vector<long long> ndp(2 * n + 1, inf);
		if(i.second == 1) {
			long long opt = inf;
			for(int j = 0; j <= 2 * n; ++j) {
				ndp[j] = min(ndp[j], opt - (long long)(abs(j - n)) * i.first);
				opt = min(opt, dp[j] + (long long)(abs(j - n)) * i.first);
			}
		}
		else {
			long long opt = inf;
			for(int j = 2 * n; j >= 0; --j) {
				ndp[j] = min(ndp[j], opt - (long long)(abs(j - n)) * i.first);
				opt = min(opt, dp[j] + (long long)(abs(j - n)) * i.first);
			}
		}
		dp = ndp;
	}
	return dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Execution timed out 1050 ms 8932 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Execution timed out 1057 ms 11864 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Execution timed out 1048 ms 11140 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 356 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Execution timed out 1050 ms 8932 KB Time limit exceeded
20 Halted 0 ms 0 KB -