Submission #412149

# Submission time Handle Problem Language Result Execution time Memory
412149 2021-05-26T14:54:05 Z cpp219 Palembang Bridges (APIO15_bridge) C++14
100 / 100
110 ms 11064 KB
#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 "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;
        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,sz = cand.size();
        if (sz <= 1) inc = 0;
        for (ll i = 1;i <= sz;i++) inc = min(inc,kq[i][0] + kq[sz - i][1]);
        ans += inc;
    }
    cout<<ans;
}

Compilation message

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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 44 ms 8652 KB Output is correct
13 Correct 84 ms 8636 KB Output is correct
14 Correct 71 ms 8096 KB Output is correct
15 Correct 50 ms 4796 KB Output is correct
16 Correct 41 ms 8672 KB Output is correct
17 Correct 82 ms 8740 KB Output is correct
18 Correct 51 ms 8732 KB Output is correct
19 Correct 104 ms 8724 KB Output is correct
20 Correct 63 ms 8844 KB Output is correct
21 Correct 88 ms 8800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 40 ms 9492 KB Output is correct
26 Correct 70 ms 9604 KB Output is correct
27 Correct 82 ms 10460 KB Output is correct
28 Correct 99 ms 11064 KB Output is correct
29 Correct 86 ms 11044 KB Output is correct
30 Correct 44 ms 5644 KB Output is correct
31 Correct 40 ms 10424 KB Output is correct
32 Correct 84 ms 10992 KB Output is correct
33 Correct 44 ms 10684 KB Output is correct
34 Correct 110 ms 11016 KB Output is correct
35 Correct 77 ms 10556 KB Output is correct
36 Correct 89 ms 10804 KB Output is correct
37 Correct 31 ms 9424 KB Output is correct