#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 3e5 + 7;
int n, k;
vector<pii> seg;
ll res = 0;
namespace sub1 {
ll pre[N], suf[N];
int pre_cnt[N], suf_cnt[N];
vector<int> E;
int idx(int x) {
return lower_bound(all(E), x) - E.begin() + 1;
}
void buildE() {
set<int> s;
for (auto x : seg) {
s.insert(x.X);
s.insert(x.Y);
}
E = vector<int>(s.begin(), s.end());
}
void Process() {
buildE();
int m = (int)E.size();
ll ANS = 9e18;
for (auto x : E) {
ll ans = res;
for (auto tmp : seg)
if (tmp.Y < x) ans+=2LL * (x - tmp.Y) + 1; else
if (tmp.X > x) ans+=2LL * (tmp.X - x) + 1; else ans++;
minimize(ANS, ans);
}
cout<<ANS;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>k>>n;
FOR(i, 1, n) {
char P, Q;
int A, B;
cin>>P>>A>>Q>>B;
res+=abs(A - B);
if (P != Q) seg.push_back({min(A, B), max(A, B)});
}
if (k == 1) {
sub1::Process();
return 0;
}
return 0;
}
Compilation message
bridge.cpp: In function 'void sub1::Process()':
bridge.cpp:67:13: warning: unused variable 'm' [-Wunused-variable]
67 | int m = (int)E.size();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |