#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
int n,k;
cin>>k>>n;
char a,b;
int x,y,ans=0;
if(k==1){
int sum=0;
vector<int> cnt(n);
vector<pair<int,int>> events;
for(int i=0;i<n;i++){
cin>>a>>x>>b>>y;
if(a==b){
ans+=abs(y-x);
continue;
}
events.push_back({x,i});
events.push_back({y,i});
sum+=x+y;
}
sort(events.begin(),events.end());
int r=events.size()/2,l=0;
int cur=ans+sum+r,last=0;
//cout<<sum<<'\n';
ans=cur;
for(int i=0;i<events.size();i++){
int u=events[i].first,p=events[i].second;
cnt[p]++;
cur-=(u-last)*2*r;
cur+=(u-last)*2*l;
ans=min(ans,cur);
if(cnt[p]==2)l++;
else r--;
last=u;
//cout<<cur<<'\n';
}
cout<<ans<<'\n';
}
}
Compilation message
bridge.cpp: In function 'int main()':
bridge.cpp:30:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0;i<events.size();i++){
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
55 ms |
5948 KB |
Output is correct |
13 |
Correct |
105 ms |
7044 KB |
Output is correct |
14 |
Correct |
75 ms |
6324 KB |
Output is correct |
15 |
Correct |
61 ms |
4072 KB |
Output is correct |
16 |
Correct |
81 ms |
6512 KB |
Output is correct |
17 |
Correct |
91 ms |
6956 KB |
Output is correct |
18 |
Correct |
91 ms |
6868 KB |
Output is correct |
19 |
Correct |
101 ms |
7080 KB |
Output is correct |
20 |
Correct |
88 ms |
6624 KB |
Output is correct |
21 |
Correct |
95 ms |
6716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |