제출 #45010

#제출 시각아이디문제언어결과실행 시간메모리
45010RezwanArefin01Palembang Bridges (APIO15_bridge)C++17
22 / 100
174 ms20940 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; vector<ii> v; ll get(ll x) { ll ret = 0; for(ii a : v) ret += abs(a.first - x) + abs(a.second - x); return ret; } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int k, n; cin >> k >> n; ll pre = 0; vector<int> pos; for(int i = 0; i < n; i++) { char p, q; int s, t; cin >> p >> s >> q >> t; if(p == q) pre += abs(s - t); else v.push_back({s, t}), pos.push_back(s), pos.push_back(t); } int m = pos.size(); if(m){ sort(pos.begin(), pos.end()); ll mn = get(pos[m/2]); if(m/2+1 < m) mn = min(mn, get(pos[m/2 + 1])); cout << mn + v.size() + pre << endl; } else cout << pre << 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...