Submission #905936

# Submission time Handle Problem Language Result Execution time Memory
905936 2024-01-13T07:27:04 Z Muhammad_Aneeq Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 496 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
bool comp(pair<int,int>a,pair<int,int>b)
{
	return (b.second>a.second);
}
void solve()
{
	int k,n;
	cin>>k>>n;
	long long ans=0;
	int z=0;
	vector<int>f;
	for (int i=0;i<n;i++)
	{
		char a,b;
		int x,y;
		cin>>a>>x>>b>>y;
		if (a==b)
			ans+=abs(x-y);
		else
		{
			z+=abs(x-y);
			f.push_back(x);
			f.push_back(y);
		}	
	}
	sort(begin(f),end(f));
	int pre[f.size()+1]={};
	for (int i=0;i<f.size();i++)
		pre[i+1]=pre[i]+f[i];
	long long r=1e15+10;
	for (auto i:f)
	{
		long long t=0;
		int g=lower_bound(begin(f),end(f),i)-begin(f);
		t+=pre[f.size()]-pre[g]-i*(f.size()-g);
		t+=i*(g+1)-pre[g+1];
		r=min(r,t);
	}
	ans+=r;
	cout<<ans+f.size()/2<<endl;
}
signed main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}

Compilation message

bridge.cpp: In function 'void solve()':
bridge.cpp:39:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for (int i=0;i<f.size();i++)
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -