제출 #523171

#제출 시각아이디문제언어결과실행 시간메모리
523171vonatlusPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms332 KiB
/// adil sultanov | vonat1us #pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:36777216") #include<bits/stdc++.h> #define x first #define y second #define pb push_back #define sz(x) (int) x.size() #define all(z) (z).begin(), (z).end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1e9 + 1e2; void fin() { #ifdef AM freopen(".in", "r", stdin); #endif } const bool flag = 0; const int N = 1e5+10; void ma1n() { int k, n; cin >> k >> n; if (k == 2) return; ll ans = 0; vector<pii> v; vector<int> all; for (int i = 0; i < n; ++i) { char c1, c2; int l, r; cin >> c1 >> l >> c2 >> r; if (l > r) swap(l, r); ans += r-l; if (c1 != c2) { ans++; v.pb({l, r}); all.pb(l); all.pb(r); } } n = sz(v); sort(all(all)); all.erase(unique(all(all)), all.end()); int mid = all[sz(all)/2]; ll mn = (1ll<<50); for (int i = -10; i <= 10; ++i) { ll res = 0, x = mid+i; for (auto [l, r] : v) { if (x < l) { res += (l-x)*2ll; } if (x > r) { res += (x-r)*2ll; } } mn = min(mn, res); } cout << ans + mn; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr), fin(); int ts = 1; if (flag) { cin >> ts; } while (ts--) { ma1n(); } return 0; }
#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...