#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int k,n;ll re=0;
map<ll,int>st,en;
ll no=0,fin=0;vector<ll>v;
int main()
{
cin>>k>>n;ll w=0;
for(int i=0;i<n;i++)
{
char a,b;
int x,y;
cin>>a>>x>>b>>y;
re+=abs(x-y);
if(a==b)continue;
re-=(abs(x-y));
re++;
if(x>y)swap(x,y);
v.pb(x);v.pb(y);
st[x]++;
st[y];no++;
en[y]++;w+=x;
}
ll mn=1e18;
ll last=0;
sort(v.begin(),v.end());
ll r=0;
for(int i=0;i<v.size();i++)
{
r+=abs(v[i]-v[v.size()/2]);
}
for(auto it:v)
{ ll z=0;
for(int i=0;i<v.size();i++)
{
z+=(abs(v[i]-it));
}
mn=min(mn,z);
/*
w+=fin*(it.fi-last);
w-=no*(it.fi-last);
fin+=en[it.fi];
no-=st[it.fi];
mn=min(mn,w);last=it.fi;
*/
}
re+=r;
cout<<re;
}
Compilation message
bridge.cpp: In function 'int main()':
bridge.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
bridge.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
bridge.cpp:29:8: warning: unused variable 'last' [-Wunused-variable]
29 | ll last=0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
80 ms |
2444 KB |
Output is correct |
13 |
Correct |
333 ms |
20636 KB |
Output is correct |
14 |
Correct |
125 ms |
3512 KB |
Output is correct |
15 |
Correct |
164 ms |
12200 KB |
Output is correct |
16 |
Correct |
116 ms |
2360 KB |
Output is correct |
17 |
Correct |
219 ms |
20644 KB |
Output is correct |
18 |
Correct |
193 ms |
20892 KB |
Output is correct |
19 |
Correct |
281 ms |
19972 KB |
Output is correct |
20 |
Correct |
102 ms |
2448 KB |
Output is correct |
21 |
Correct |
210 ms |
20516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
248 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |