Submission #698967

#TimeUsernameProblemLanguageResultExecution timeMemory
698967nguyentunglamPalembang Bridges (APIO15_bridge)C++17
8 / 100
2082 ms2968 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; pair<int, int> a[N]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int k, n; cin >> k >> n; long long res = 0, total = 1e18; int cnt = 0; for(int i = 1; i <= n; i++) { char p, q; int s, t; cin >> p >> s >> q >> t; if (p != q) { if (s > t) swap(s, t); a[++cnt] = make_pair(s, t); res++; } res += abs(s - t); } vector<int> lst; for(int i = 1; i <= n; i++) lst.push_back(a[i].fi), lst.push_back(a[i].se); for(int &j : lst) { long long ans = 0; for(int i = 1; i <= cnt; i++) { if (j < a[i].fi) ans += 2 * (a[i].fi - j); if (j > a[i].se) ans += 2 * (j - a[i].se); } total = min(total, res + ans); } cout << total << endl; }

Compilation message (stderr)

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