Submission #39771

#TimeUsernameProblemLanguageResultExecution timeMemory
3977114kgPalembang Bridges (APIO15_bridge)C++11
0 / 100
1 ms1952 KiB
#include <stdio.h> #include <algorithm> #include <queue> #include <vector> #include <functional> #define N 100001 #define min2(x,y) (x<y?x:y) using namespace std; typedef pair<int, pair<int, int> > pip; int n, K, out; pair<int, int> in[N]; priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q; void f1() { int x1 = n, x2 = 0, w = 0, sum = 0, tot; for (int i = 1; i <= n; i++) { sum += in[i].first; Q.push({ in[i].first,1 }), Q.push({ in[i].second,2 }); } tot = sum * 2; while (!Q.empty()) { sum -= (Q.top().first - w)*x1, sum += (Q.top().first - w)*x2; tot = min2(tot, sum * 2), w = Q.top().first; if (Q.top().second == 1) x1--; else x2++; Q.pop(); } out += tot; } int main() { // freopen("input.txt", "r", stdin); int k, x, y; char in_a, in_b; scanf("%d %d ", &K, &k); while (k--) { scanf("%c %d %c %d ", &in_a, &x, &in_b, &y); if (x > y) x += y, y = x - y, x -= y; out += y - x; if (in_a != in_b) out++, in[++n] = { x,y }; } if (K == 1) f1(); printf("%d", out); }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:36:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d ", &K, &k);
                         ^
bridge.cpp:38:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %d %c %d ", &in_a, &x, &in_b, &y);
                                              ^
#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...