Submission #411937

#TimeUsernameProblemLanguageResultExecution timeMemory
411937cpp219Palembang Bridges (APIO15_bridge)C++14
8 / 100
2057 ms5148 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 9; const ll Log2 = 20; const ll inf = 1e16 + 7; typedef pair<ll,ll> LL; vector<ll> v; ll k,n,ans,inc,in[N],out[N]; struct human{ char x,y; ll L,R; }; human a[N]; ll Find(ll x){ return lower_bound(v.begin(),v.end(),x) - v.begin() + 1; } void compress(){ sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin()); //for (ll i = 1;i <= n;i++) a[i].L = Find(a[i].L),a[i].R = Find(a[i].R); } ll bit1[N],bit2[N]; void upd(ll p,ll val,ll bit[]){ for (ll i = p;i < N;i += i & -i) bit[i] += val; } ll Get(ll p,ll bit[]){ ll res = 0; for (ll i = p;i > 0;i -= i & -i) res += bit[i]; return res; } ll cal_opt(ll opt){ ll inc = 0; for (ll i = 1;i <= n;i++){ if (a[i].x == a[i].y) continue; if (a[i].L > opt) inc += 2*(a[i].L - opt); if (a[i].R < opt) inc += 2*(opt - a[i].R); } return inc; } void Sub1(){ ll inc = inf; for (ll i = 1;i <= n;i++) inc = min(inc,cal_opt(a[i].L)),inc = min(inc,cal_opt(a[i].R)); cout<<ans + inc; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>k>>n; for (ll i = 1;i <= n;i++){ cin>>a[i].x>>a[i].L>>a[i].y>>a[i].R; if (a[i].L > a[i].R) swap(a[i].L,a[i].R); ans += a[i].R - a[i].L; v.push_back(a[i].L); v.push_back(a[i].R); if (a[i].x != a[i].y) ans++; } compress(); Sub1(); }

Compilation message (stderr)

bridge.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
bridge.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
bridge.cpp: In function 'int main()':
bridge.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...