Submission #160793

# Submission time Handle Problem Language Result Execution time Memory
160793 2019-10-30T02:11:15 Z sofhiasouza Cover (COCI18_cover) C++14
96 / 120
7 ms 632 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
typedef pair < int, int > ii;

const int maxn = 5e3+10, inf = 2e18+10;

int n, dp[maxn];

map < int, int > mapa;

int32_t main()
{
	//cin >> n;
	scanf("%lld", &n);

	for(int i = 1 ; i <= n ; i++)
	{
		int x, y;
		//cin >> x >> y;
		scanf("%lld %lld", &x, &y);

		x = abs(x);
		y = abs(y);

		if(!mapa.count(x)) mapa[x] = y;
		else mapa[x] = max(mapa[x], y);
	}

	vector < ii > aux;

	for(auto v : mapa)
	{
		if(!aux.size() or aux[aux.size()-1].S > v.S) aux.pb(v);
		else if(aux.size())
		{
			aux.pop_back();
			aux.pb(v);
		}
	}

	dp[1] = 0;

	for(int i = 1 ; i < aux.size() ; i++)
	{
		dp[i+1] = inf;
	
		for(int j = 0 ; j < i ; j++)
		{
			dp[i+1] = min(dp[i+1], dp[j+1] + 4ll*aux[j].S*aux[i-1].F);
		}
	}

	int resp = inf;
	for(int i = 0 ; i < aux.size() ; i++)
	{
		resp = min(resp, dp[i+1] + 4ll*aux[i].S*aux[aux.size()-1].F);
	}

	printf("%lld\n", resp);
	//cout << resp << "\n";	
}

Compilation message

cover.cpp: In function 'int32_t main()':
cover.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1 ; i < aux.size() ; i++)
                  ~~^~~~~~~~~~~~
cover.cpp:58:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < aux.size() ; i++)
                  ~~^~~~~~~~~~~~
cover.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
cover.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Incorrect 5 ms 508 KB Output isn't correct
10 Incorrect 7 ms 632 KB Output isn't correct