제출 #391036

#제출 시각아이디문제언어결과실행 시간메모리
391036BlagojcePalembang Bridges (APIO15_bridge)C++11
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 4e9; const ll mod = 1e9+7; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t z; const int &mxn = 2e5+5; int n, k; vector<pair<ll, ll> > v; ll lef[mxn]; ll rig[mxn]; void solve(){ cin >> k >> n; ll sum = 0; fr(i, 0, n){ char c1, c2; ll a, b; cin >> c1 >> a >> c2 >> b; if(c1 == c2){ sum += abs(a-b); continue; } if(a > b) swap(a, b); v.pb({a, b}); sum += b-a+1; } if(k == 1){ vector<pair<ll,int> > g; for(auto u : v){ g.pb({u.st, 0}); g.pb({u.nd, 1}); } sort(all(g)); int m = g.size(); ll temp_sum = 0; int cnt = 0; fr(i, 0, m){ ll pos = g[i].st; lef[i] = pos*cnt - temp_sum; if(g[i].nd == 1){ temp_sum += pos; ++cnt; } } temp_sum = 0; cnt = 0; for(int i = m-1; i >= 0; i --){ ll pos = g[i].st; rig[i] = temp_sum - pos*cnt; if(g[i].nd == 0){ temp_sum += pos; ++cnt; } } ll ans = inf; fr(i, 0, m){ ans = min(ans, 2*(lef[i]+rig[i]) + sum); } cout<<ans<<endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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...