답안 #903860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903860 2024-01-11T12:38:08 Z math_rabbit_1028 전선 연결 (IOI17_wiring) C++14
13 / 100
47 ms 8740 KB
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<pii> arr;
vector<ll> sum;
vector<ll> dp;
ll min_total_length(vector<int> R, vector<int> B) {
	arr.push_back({0, 0});
	for (int i = 0; i < R.size(); i++) arr.push_back({R[i], 0});
	for (int i = 0; i < B.size(); i++) arr.push_back({B[i], 1});
	sort(arr.begin() + 1, arr.end());
	dp = vector<ll>(arr.size(), 1e18);
	sum = vector<ll>(arr.size(), 0);
	for (int i = 1; i < sum.size(); i++) sum[i] = sum[i - 1] + arr[i].first;

	dp[0] = 0;
	int a, b, last, i = 1;
	while (arr[i].second == arr[i+1].second) i++;
	b = i;
	for (int j = 1; j <= i; j++) dp[j] = dp[j-1] + arr[b+1].first - arr[j].first;
	for (i++; i < arr.size(); i++) {
		if (arr[i].second != arr[i-1].second) {
			a = b;
			b = 0;
			last = arr[i-1].first;
		}
		b++;
		if (b <= a) {
			dp[i] = min(dp[i], dp[i-1] + arr[i].first - last);
			dp[i] = min(dp[i], dp[i-2*b] + (sum[i] - sum[i-b]) - (sum[i-b] - sum[i-2*b]));
		}
		else {
			dp[i] = min(dp[i], dp[i-1] + arr[i].first - last);
		}
	}

	return dp[arr.size()-1];
}

Compilation message

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i = 0; i < R.size(); i++) arr.push_back({R[i], 0});
      |                  ~~^~~~~~~~~~
wiring.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < B.size(); i++) arr.push_back({B[i], 1});
      |                  ~~^~~~~~~~~~
wiring.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 1; i < sum.size(); i++) sum[i] = sum[i - 1] + arr[i].first;
      |                  ~~^~~~~~~~~~~~
wiring.cpp:24:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (i++; i < arr.size(); i++) {
      |            ~~^~~~~~~~~~~~
wiring.cpp:36:48: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |    dp[i] = min(dp[i], dp[i-1] + arr[i].first - last);
      |                                                ^~~~
wiring.cpp:31:3: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |   if (b <= a) {
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14522'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 0 ms 424 KB Output is correct
3 Correct 21 ms 6464 KB Output is correct
4 Correct 24 ms 6668 KB Output is correct
5 Correct 19 ms 6600 KB Output is correct
6 Correct 28 ms 8740 KB Output is correct
7 Correct 40 ms 8568 KB Output is correct
8 Correct 24 ms 8648 KB Output is correct
9 Correct 26 ms 8640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 47 ms 8600 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1240633149'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Incorrect 30 ms 7888 KB 3rd lines differ - on the 1st token, expected: '373710605', found: '425203133'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14522'
3 Halted 0 ms 0 KB -