Submission #880322

#TimeUsernameProblemLanguageResultExecution timeMemory
880322vjudge1Palembang Bridges (APIO15_bridge)C++17
0 / 100
3 ms600 KiB
#include <iostream> #include <fstream> #include <iomanip> #include <vector> #include <set> #include <map> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <ctime> #include <algorithm> #include <sstream> #include <list> #include <queue> #include <deque> #include <stack> #include <cstdlib> #include <cstdio> #include <iterator> #include <functional> #include <unordered_set> #include <unordered_map> #include <stdio.h> #include <bitset> #include <cstdint> #include <cassert> #include <functional> #include <complex> #include <climits> #include <random> using namespace std; #define ll long long #define pb push_back #define ull unsigned long long #define F first #define S second #define all(v) v.begin(), v.end() struct bruh{ char A, B; ll x, y; } a[20005]; void solve(){ int k, n; cin >> k >> n; ll ans = INT_MAX; vector<ll> v; for(int i = 1; i <= n; i++){ char A, B; ll x, y; cin >> A >> x; cin >> B >> y; a[i].A = A, a[i].B = B; a[i].x = x, a[i].y = y; v.pb(x), v.pb(y); } sort(all(v)); for(auto i : v){ ll bridge = i; ll cnt = 0LL; for(int j = 1; j <= n; j++){ ll x = a[j].x; ll y = a[j].y; if(a[j].A == a[j].B){ cnt += abs(x - y); continue; } cnt += abs(x - bridge) + abs(bridge - y) + 1LL; } ans = min(ans, cnt); } cout << ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int xach = 1; //cin >> xach; while(xach--) solve(); } /* * */
#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...