Submission #851790

#TimeUsernameProblemLanguageResultExecution timeMemory
851790KavelmydexPalembang Bridges (APIO15_bridge)C++17
0 / 100
0 ms440 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector <ll> vi; typedef pair <int,int> pi; #define pb push_back #define f first #define s second #define OO 1e9 #define all(x) (x).begin(), (x).end() int main() { // ios::sync_with_stdio(0); cin.tie(0); // freopen("art2.in", "r", stdin); // freopen("art2.out", "w", stdout); int n, k; cin >> k >> n; vector <pi> home(n), work(n); for(int i=0; i<n; ++i){ int h, w;char a, b; cin >> a >> h >> b >> w; home[i].f = h; home[i].s = (a == 'A'); work[i].f = w; work[i].s = (b == 'A'); } vi v; for(int i=0; i<n; ++i){v.pb(home[i].f); v.pb(work[i].f);} sort(all(v)); v.resize(unique(all(v)) - v.begin()); int median = v[(v.size()-1)/2]; ll ans = 0; cout << median << "\n"; for(int i=0; i<n; ++i){ if(home[i].s == work[i].s){ ans += abs(home[i].f - work[i].f); continue; } ans += (abs(home[i].f-median) + abs(median-work[i].f)+1); } median++; ll sum=0; for(int i=0; i<n; ++i){ if(home[i].s == work[i].s){ sum += abs(home[i].f - work[i].f); continue; } sum += (abs(home[i].f-median) + abs(median-work[i].f)+1); } cout << min(ans,sum); 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...