Submission #39772

#TimeUsernameProblemLanguageResultExecution timeMemory
3977214kgPalembang Bridges (APIO15_bridge)C++11
22 / 100
84 ms5108 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; long long 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; long long sum = 0, tot; for (int i = 1; i <= n; i++) { sum += (long long)in[i].first; Q.push({ in[i].first,1 }), Q.push({ in[i].second,2 }); } tot = sum * 2; while (!Q.empty()) { sum += (long long)(Q.top().first - w)*(long long)(x2 - x1); 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 += (long long)(y - x); if (in_a != in_b) out++, in[++n] = { x,y }; } if (K == 1) f1(); printf("%lld", out); }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:38: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:40: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...