제출 #1014183

#제출 시각아이디문제언어결과실행 시간메모리
1014183aykhn전선 연결 (IOI17_wiring)C++17
7 / 100
1098 ms8648 KiB
#include "wiring.h"
#include <bits/stdc++.h>

using namespace std;

long long min_total_length(vector<int> r, vector<int> b) 
{
	vector<array<long long, 2>> a;
	int i = 0, j = 0;
	while (i < r.size() && j < b.size())
	{
		if (r[i] <= b[j]) a.push_back({r[i++], 0});
		else a.push_back({b[j++], 1});
	}
	while (i < r.size()) a.push_back({r[i++], 0});
	while (j < b.size()) a.push_back({b[j++], 1});
	vector<long long> dp(a.size(), 1e18);
	for (int i = 0; i < a.size(); i++)
	{
		long long mn = 1e18;
		for (int j = 0; j < a.size(); j++)
		{
			if (a[i][1] != a[j][1]) mn = min(mn, abs(a[i][0] - a[j][0]));
		}
		dp[i] = (i ? dp[i - 1] : 0) + mn;
		long long cntr = 0, cntb = 0, d = 0;
		for (int j = i; j >= 0; j--)
		{
			if (a[j][1] == 0)
			{
				if (cntb > cntr) d -= a[j][0];
				else d += a[j][0];
				cntr++;
			}
			else
			{
				if (cntr > cntb) d -= a[j][0];
				else d += a[j][0];
				cntb++;
			}
			if (cntr == cntb) dp[i] = min(dp[i], (j ? dp[j - 1] : 0) + d);
		}
	}
	return dp[(int)a.size() - 1];

}

컴파일 시 표준 에러 (stderr) 메시지

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:10:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  while (i < r.size() && j < b.size())
      |         ~~^~~~~~~~~~
wiring.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  while (i < r.size() && j < b.size())
      |                         ~~^~~~~~~~~~
wiring.cpp:15:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  while (i < r.size()) a.push_back({r[i++], 0});
      |         ~~^~~~~~~~~~
wiring.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  while (j < b.size()) a.push_back({b[j++], 1});
      |         ~~^~~~~~~~~~
wiring.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
wiring.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int j = 0; j < a.size(); j++)
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...