Submission #412148

#TimeUsernameProblemLanguageResultExecution timeMemory
412148cpp219Palembang Bridges (APIO15_bridge)C++14
22 / 100
94 ms9916 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; struct human{ char x,y; ll L,R; }; human a[N]; ll kq[N][2]; vector<LL> cand; bool lf(LL x,LL y){ return x.fs + x.sc < y.fs + y.sc; } void oper(ll cond){ priority_queue<ll> pq1; priority_queue<ll,vector<ll>,greater<ll>> pq2; ll sm = 0,bg = 0; for (ll i = 0;i < cand.size();i++){ LL now = cand[i]; pq1.push(now.fs); pq2.push(now.sc); while(pq1.top() > pq2.top()){ ll x = pq1.top(),y = pq2.top(); bg += x - y; sm += y - x; pq1.pop(); pq2.pop(); pq1.push(y); pq2.push(x); } //cout<<pq1.top()<<"\n"; kq[i + 1][cond] = bg - sm; //cout<<kq[i + 1][cond]<<"\n"; } //exit(0); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" 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; if (a[i].x != a[i].y) ans++,cand.push_back({a[i].L,a[i].R}); } sort(cand.begin(),cand.end(),lf); oper(0); reverse(cand.begin(),cand.end()); oper(1); if (k == 1) ans += kq[cand.size()][0]; else{ ll inc = inf; if (n == 1) inc = 0; for (ll i = 1;i < n;i++) inc = min(inc,kq[i][0] + kq[n - i][1]); ans += inc; } cout<<ans; }

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 'void oper(long long int)':
bridge.cpp:33:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (ll i = 0;i < cand.size();i++){
      |                   ~~^~~~~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         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...