Submission #112162

# Submission time Handle Problem Language Result Execution time Memory
112162 2019-05-17T16:02:57 Z Runtime_error_ Palembang Bridges (APIO15_bridge) C++14
22 / 100
114 ms 4384 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll k,n,ans,cnt,sum2;
vector<ll> v;

int main(){

    cin>>k>>n;
    for(ll i=1;i<=n;i++){
        char x,y;
        ll a,b;
        cin>>x>>a>>y>>b;
        if(x==y)
            ans+=abs(a-b);
        else
            v.push_back(a),v.push_back(b),cnt+=2,sum2+=a+b;
    }
    ans+=cnt/2;
    if(cnt){
        ll temp=1e18+9;
        sort(v.begin(),v.end());
        ll sum1=0,sz=v.size();
        for(ll i=0;i<v.size();i++)
            sum1+=v[i],sum2-=v[i],temp=min(temp,(ll)(i+1ll)*v[i]-sum1 + sum2-(sz-i-1ll)*v[i] );
        ans+=temp;
    }
    cout<<ans<<endl;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:25:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(ll i=0;i<v.size();i++)
                    ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 54 ms 2540 KB Output is correct
13 Correct 114 ms 4384 KB Output is correct
14 Correct 76 ms 3688 KB Output is correct
15 Correct 68 ms 2796 KB Output is correct
16 Correct 83 ms 3768 KB Output is correct
17 Correct 104 ms 4324 KB Output is correct
18 Correct 98 ms 4076 KB Output is correct
19 Correct 112 ms 4332 KB Output is correct
20 Correct 92 ms 3848 KB Output is correct
21 Correct 106 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -