Submission #23485

#TimeUsernameProblemLanguageResultExecution timeMemory
23485duongthoi1999Palembang Bridges (APIO15_bridge)C++14
22 / 100
63 ms4912 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef long long ll; typedef long double ld; typedef pair<int, int> ii; const int mod = (int) 1e9 + 7; const ll inf = 1LL << 60; const int maxn = (int) 1e5 + 5; const ld eps = 1e-9; int n, k; vector<ii> a; vector<int> v; ll add, res; int main() { //freopen("test.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cin >> k >> n; rep(i, 1, n + 1) { char x, y; int l, r; cin >> x >> l >> y >> r; if(l > r) swap(l, r); if(x == y) add += r - l; else { a.pb(ii(l, r)); v.pb(l); v.pb(r); } } if(!v.empty()) { sort(all(v)); int p = v[SZ(v) / 2]; for (auto i : a) res += 1 + abs(i.fi - p) + abs(i.se - p); } res += add; cout << res << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...