Submission #585468

#TimeUsernameProblemLanguageResultExecution timeMemory
585468messiuuuuuPalembang Bridges (APIO15_bridge)C++17
22 / 100
47 ms2672 KiB
#include<bits/stdc++.h> #define task "A" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 1e5 + 5; const ll INF = 1e18 + 5; int n, k; struct TRoad { char h, o; ll ph, po; }a[MAXN]; void Input() { cin >> k >> n; for (int i = 1; i <= n; i++) { cin >> a[i].h >> a[i].ph >> a[i].o >> a[i].po; } } ll Cal1(int c1, int c2) { ll res = 0; for (int i = 1; i <= n; i++) { if (a[i].h == a[i].o) { res += abs(a[i].ph - a[i].po); } else { res += min(abs(a[i].ph - c1) + abs(a[i].po - c1) + 1, abs(a[i].ph - c2) + abs(a[i].po - c2) + 1); } } return res; } ll Cal(int p) { if (k == 1) { return Cal1(p, -2e9); } int l = p + 1, r = 1e9; while (l <= r) { int mid = (l + r) / 2; if (mid == 1e9) break; if (Cal1(p, mid) > Cal1(p, mid + 1)) { l = mid + 1; } else r = mid - 1; } //cout << l << '\n'; return Cal1(p, l); } void Solve() { int l = 0, r = 1e9; //cout << Cal(4) << '\n'; while (l <= r) { int mid = (l + r) / 2; if (mid == 1e9) break; if (Cal(mid) >= Cal(mid + 1)) l = mid + 1; else r = mid - 1; } cout << Cal(l); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".INP","r")) { freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } Input(); Solve(); }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...