Submission #336168

#TimeUsernameProblemLanguageResultExecution timeMemory
336168super_j6Palembang Bridges (APIO15_bridge)C++14
22 / 100
63 ms4480 KiB
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define endl '\n' #define ll long long #define pi pair<int, int> #define f first #define s second const int mxn = 100000; int n, k; vector<pi> p; vector<int> v; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> k >> n; ll ret = 0; for(int i = 0; i < n; i++){ char a, b; int x, y; cin >> a >> x >> b >> y; if(x > y) swap(x, y); ret += y - x; if(a != b) ret++, p.push_back({x, y}), v.push_back(x), v.push_back(y); } sort(v.begin(), v.end()); if(!v.empty()){ int x = v[v.size() / 2]; for(pi i : p){ if(x < i.f) ret += 2 * (i.f - x); if(x > i.s) ret += 2 * (x - i.s); } } cout << ret << endl; 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...