Submission #1069510

# Submission time Handle Problem Language Result Execution time Memory
1069510 2024-08-22T04:13:38 Z Luvidi Palembang Bridges (APIO15_bridge) C++17
0 / 100
2 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back

void solve() {
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    int br,n;
    cin>>br>>n;
    vector<pll> seg;
    ll sum=0;
    while(n--){
        char x,y;
        ll a,b;
        cin>>x>>a>>y>>b;
        if(a>b)swap(a,b);
        if(x==y)sum+=b-a;
        else{
            seg.pb({a,b});
            sum++;
        }
    }
    n=seg.size();
    if(!n){
        cout<<sum;
        return;
    }
    if(br==1){
        ll ans=1e18;
        for(int i=0;i<n;i++){
            ll s=0;
            for(int j=0;j<n;j++){
                s+=abs(seg[j].fs-seg[i].fs)+abs(seg[i].fs-seg[j].sc);
            }
            ans=min(ans,s);
        }
        cout<<sum+ans;
    }else{
        ll ans=1e18;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                ll s=0;
                for(int k=0;k<n;k++){
                    s+=min(abs(seg[k].fs-seg[i].fs)+abs(seg[i].fs-seg[k].sc),abs(seg[k].fs-seg[j].fs)+abs(seg[j].fs-seg[k].sc));
                }
                ans=min(ans,s);
            }
        }
        cout<<sum+ans;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();
}

Compilation message

bridge.cpp: In function 'void solve()':
bridge.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen("in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~
bridge.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -