제출 #493765

#제출 시각아이디문제언어결과실행 시간메모리
493765sberensPalembang Bridges (APIO15_bridge)C++17
22 / 100
39 ms5576 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename K> using hset = gp_hash_table<K, null_type>; template<typename K, typename V> using hmap = gp_hash_table<K, V>; using namespace std; #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define smax(x, y) (x = max(x, y)) #define smin(x, y) (x = min(x, y)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i,0,a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i,0,a) using ll = long long; using ld = long double; template<typename T> using vv = vector<vector<T>>; using vi = vector<int>; using ii = array<int, 2>; using vii = vector<ii>; using vvi = vv<int>; using vll = vector<ll>; using l2 = array<ll, 2>; using vl2 = vector<l2>; using vvll = vv<ll>; template<typename T> using minq = priority_queue<T, vector<T>, greater<T>>; template<typename T> using maxq = priority_queue<T>; const ll M = 1000000007; const ll infll = M * M; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; cin >> k >> n; ll res{}; vii pe; F0R(i, n) { char p, q; int s, t; cin >> p >> s >> q >> t; if (p == q) res += abs(t - s); else pe.pb({s, t}); } if (k == 1) { if (pe.empty()) { cout << res << '\n'; return 0; } res += pe.size(); // distance from people crossing the bridge vll v; for (auto [s, t] : pe) { v.pb(s); v.pb(t); } sort(all(v)); ll x = (v[v.size() / 2 - 1] + v[v.size() / 2]) / 2; for (auto [s, t] : pe) { res += abs(s - x) + abs(t - x); } cout << res << '\n'; } }
#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...