#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
//const int mod = 1000000007;
//Note to self: Check for overflow
vector<pii> segs;
map<int,li> stat;
map<int,li> koef;
set<int> kords;
li solve1()
{
int n=(int)segs.size();
for (auto [l,r] : segs)
{
kords.insert(l),kords.insert(r+1);
stat[0]+=r,stat[r+1]-=r,koef[0]--,koef[r+1]++; //adduje jednu pravu y=-x + qrac
koef[l]++; //adduje drugu pravu y=x + qrac
}
li k=0,s=0,ans=3e18;
for (auto x : kords)
{
k+=koef[x],s+=stat[x];
ans=min(ans,k*x+s);
}
return ans;
}
li solve2()
{
return 0ll;
}
int main()
{
FAST;
li neces=0;
int k,n; cin>>k>>n;
ff(i,0,n)
{
char _,__; int a,b;
cin>>_>>a>>__>>b;
if (a>b) swap(a,b);
if (_!=__) segs.pb({a,b});
else neces+=b-a;
}
if (k==1) cout<<neces+solve1()<<"\n";
else cout<<neces+solve2()<<"\n";
}
//Note to self: Check for overflow
Compilation message
bridge.cpp: In function 'li solve1()':
bridge.cpp:44:9: warning: unused variable 'n' [-Wunused-variable]
44 | int n=(int)segs.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |