Submission #317886

#TimeUsernameProblemLanguageResultExecution timeMemory
317886ali_tavakoliPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms416 KiB
//In the name of Allah #include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() const int N = 1e5 + 5; int n, k, med[N][2]; vector<pair<int, pair<int, int> > > ve; int main() { priority_queue<int> q1; priority_queue<int, vector<int>, greater<int> > q2; q1.push(0);q1.push(1); cout << q1.top(); cin >> k >> n; for(int i = 0; i < n; i++) { char ch1, ch2; int p, q; cin >> ch1 >> p >> ch2 >> q; if(ch1 != ch2) ve.pb({p + q, {min(p, q), max(p, q)}}); } sort(all(ve)); for(int i = 0; i < ve.size(); i++) { auto x = ve[i]; q1.push(x.S.F); q2.push(x.S.S); while(q1.top() > q2.top()) { int to1 = q1.top(), to2 = q2.top(); q1.pop();q2.pop(); q1.push(to2); q2.push(to1); } med[i][0] = q1.top(); med[i][1] = q2.top(); } if(k == 1) { ll ans1, ans2; ans1 = ans2 = 0; for(int i = 0; i < n; i++) { ans1 += abs(ve[i].S.F - med[n - 1][0]); ans1 += abs(ve[i].S.S - med[n - 1][0]); ans2 += abs(ve[i].S.F - med[n - 1][1]); ans2 += abs(ve[i].S.S - med[n - 1][1]); } cout << min(ans1, ans2) << endl; } }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < ve.size(); i++)
      |                    ~~^~~~~~~~~~~
#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...