Submission #396283

#TimeUsernameProblemLanguageResultExecution timeMemory
396283SavicSPalembang Bridges (APIO15_bridge)C++14
22 / 100
46 ms4432 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 100005; const ll inf = 1e18 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, K; array<int,4> niz[maxn]; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> K >> n; vector<int> vec; vector<pii> A; ll rez = 0; ff(i,1,n) { int S, T; char p, q; cin >> p >> S >> q >> T; int P = p - 'A', Q = q - 'A'; if(P == Q)rez += abs(T - S); else { vec.pb(S), vec.pb(T); A.pb({S, T}); } } if(!sz(vec))return cout << rez, 0; sort(all(vec)); int ivo = vec[sz(vec) / 2]; for(auto c : A) { int S = c.fi; int T = c.se; rez += abs(S - ivo) + abs(T - ivo) + 1; } cout << rez << endl; return 0; } /** 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 // probati bojenje sahovski ili slicno **/
#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...