Submission #1028620

# Submission time Handle Problem Language Result Execution time Memory
1028620 2024-07-20T06:18:35 Z vjudge1 Palembang Bridges (APIO15_bridge) C++17
22 / 100
119 ms 17228 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int M = 1e5 + 1;

int pre[M]={},pre1[M]={},n;

int get(int a,vector<int> &v)
{
	int x=upper_bound(v.begin(),v.end(),a)-v.begin();
	return abs(a*x-pre[x]+pre[n]-pre[x]-(n-x)*a);
}

int get1(int a,vector<int> &v)
{
	int x=upper_bound(v.begin(),v.end(),a)-v.begin();
	return abs(a*x-pre1[x]+pre1[n]-pre1[x]-(n-x)*a);
}

signed main()
{
	int k,su=0;
	cin>>k>>n;
	vector<int> v,v1;
	for (int i=0;i<n;i++)
	{
		char c,c1;
		int x,y;
		cin>>c>>x>>c1>>y;
		if (c==c1)
			su+=abs(y-x);
		else
		{
			if (c=='B')
				swap(x,y);
			v.push_back(x);
			v1.push_back(y);
		}
	}
	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	n=v.size();
	set<int> se;
	for (int i=0;i<n;i++)
		pre[i+1]=pre[i]+v[i],pre1[i+1]=pre1[i]+v1[i],se.insert(v[i]),se.insert(v1[i]);
	vector<int> pos;
	int ans=n*1e9;
	for (int i:se)
		pos.push_back(i);
	for (int i=0;i<pos.size();i++)
		ans=min(ans,get(pos[i],v)+get1(pos[i],v1));
	cout<<ans+su+n<<endl;
	
	return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:53: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]
   53 |  for (int i=0;i<pos.size();i++)
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 400 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 31 ms 4384 KB Output is correct
13 Correct 119 ms 17216 KB Output is correct
14 Correct 57 ms 5088 KB Output is correct
15 Correct 84 ms 10148 KB Output is correct
16 Correct 47 ms 5320 KB Output is correct
17 Correct 106 ms 17228 KB Output is correct
18 Correct 99 ms 16852 KB Output is correct
19 Correct 114 ms 16952 KB Output is correct
20 Correct 52 ms 5464 KB Output is correct
21 Correct 110 ms 17004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -