Submission #685173

#TimeUsernameProblemLanguageResultExecution timeMemory
685173omikron123Palembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms340 KiB
// https://oj.uz/problem/view/APIO15_bridge #include <cstdio> #include <algorithm> #include <functional> #include <vector> #include <cstring> #include <cmath> using namespace std; typedef long long ll; // K=1,2, N=1e5 // 1. 家和办公室在同一边的是不参与计算的,和桥没有关系。 // 2. 最小值都在event点上面取得,而且是一个U型的阶梯函数,所以应该可以固定一个桥的位置,然后binary search另外一个。 // 3. 进一步可以发现K=1的时候,答案就是S[i], T[i]的median. 这已经可以得2/3的分了。 int n, K; ll ans; vector<pair<int,int>> x; int main() { scanf("%d %d", &K, &n); for (int i = 0; i < n; i++) { char c1[10], c2[10]; int x1, x2; scanf("%s %d %s %d", c1, &x1, c2, &x2); if (c1[0] == c2[0]) ans += abs(x1-x2); else x.push_back({min(x1,x2), max(x1,x2)}); } if (K == 1) { // just return the median of all numbers vector<int> X; for (auto p: x) { X.push_back(p.first); X.push_back(p.second); } sort(X.begin(), X.end()); int m = X[X.size() / 2]; for (auto p: x) { ans += abs(p.first-m) + abs(p.second-m); } } else { } printf("%lld", ans); return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d", &K, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%s %d %s %d", c1, &x1, c2, &x2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...