Submission #838955

# Submission time Handle Problem Language Result Execution time Memory
838955 2023-08-28T10:55:44 Z drkarlicio2107 Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 232 KB
#include <bits/stdc++.h>
using namespace std;
vector < pair <int, int> > v;
int pos [20010][2];
int main (){
    int n, k; cin >> k >> n; long long int sol=0; int ind=0;
    for (int i=0; i<n; i++){
        long long int a, b; char x, y; cin >> x >> a >> y >> b;
        if (x==y){
            sol+=abs (a-b); continue;
        }
        v.push_back ({a, 0});
        v.push_back ({b, 1}); pos [ind][0]=a; pos [ind][1]=b; ind++;
    }
    long long int ans=1e18;
    for (int i=0; i<v.size(); i++){
        int po=v [i].first; long long int curr=0;
        for (int j=0; j<ind; j++){
            if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=2*min (abs (pos [j][0]-po), abs (pos [j][1]-po));
            curr+=(abs (pos [j][0]-pos [j][1])+1);
        }
        ans=min (ans, curr);

        po=v [i].first-1; curr=0;
        for (int j=0; j<ind; j++){
            if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=2*min (abs (pos [j][0]-po), abs (pos [j][1]-po));
            curr+=(abs (pos [j][0]-pos [j][1])+1);
        }
        ans=min (ans, curr);

        po=v [i].first+1; curr=0;
        for (int j=0; j<ind; j++){
            if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=2*min (abs (pos [j][0]-po), abs (pos [j][1]-po));
            curr+=(abs (pos [j][0]-pos [j][1])+1);
        }
        ans=min (ans, curr);
        //cout << ans << endl;
    }
    cout << sol+ans << endl;
    return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<v.size(); i++){
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -