제출 #1014195

#제출 시각아이디문제언어결과실행 시간메모리
1014195aykhn전선 연결 (IOI17_wiring)C++17
17 / 100
1100 ms9828 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);
	vector<long long> mn(a.size(), 1e18);
	long long rl = -1e18, bl = -1e18;
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i][1] == 0) mn[i] = min(mn[i], abs(a[i][0] - bl)), rl = a[i][0];
		else mn[i] = min(mn[i], abs(a[i][0] - rl)), bl = a[i][0];
	}
	rl = 1e18, bl = 1e18;
	for (int i = (int)a.size() - 1; i >= 0; i--)
	{
		if (a[i][1] == 0) mn[i] = min(mn[i], abs(a[i][0] - bl)), rl = a[i][0];
		else mn[i] = min(mn[i], abs(a[i][0] - rl)), bl = a[i][0];
	}
	vector<int> f(a.size() * 2 + 100, 0);
	f[a.size()] = 1;
	int c = 0;
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i][1] == 0) c++;
		else c--;
		dp[i] = (i ? dp[i - 1] : 0) + mn[i];
		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);
				break;
			}
		}
		f[c + a.size()] = 1;
	}
	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:20: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]
   20 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
wiring.cpp:34: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]
   34 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
#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...