Submission #248397

#TimeUsernameProblemLanguageResultExecution timeMemory
248397sahil_kPalembang Bridges (APIO15_bridge)C++14
22 / 100
169 ms2668 KiB
// Improvement - find m using binary search #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main () { int k, n; cin >> k >> n; char ai, ci; int bi, di; long long o = 0; vector< pair<int, int> > imp; for (int i=0; i<n; i++) { cin >> ai >> bi >> ci >> di; if (ai != ci) { imp.push_back(make_pair(min(bi, di), max(bi, di))); } else { o += abs(bi-di); } } o += imp.size(); if (k == 1) { vector<int> vals; for (auto i: imp) { vals.push_back(i.first); vals.push_back(i.second); } sort(vals.begin(), vals.end()); int mid = vals[vals.size()/2]; for (auto i: vals) { o += abs(mid-i); } cout << o << 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...