Submission #1016966

# Submission time Handle Problem Language Result Execution time Memory
1016966 2024-07-08T16:33:21 Z TroySer Palembang Bridges (APIO15_bridge) C++17
22 / 100
73 ms 10076 KB
// median?
#include <bits/stdc++.h>
 
using namespace std;
 
const long long int INF = 1e18;
 
long long int K, N;
long long int build1, build2;
char zone1, zone2;
 
long long int Dmin = 0;
 
struct Place {
    char zone;
    long long int building;
};

vector<pair<Place, Place> > people;
vector<long long int> person;
 
long long int cost(long long int currK) {
    long long int currMin = 0;
    for (int j = 0; j < people.size(); j++) {
        currMin += abs(people[j].first.building - currK);
        currMin++;
        currMin += abs(people[j].second.building - currK);
    }
    return currMin;
}
 
int main() {
    cin >> K >> N;
    for (int i = 0; i < N; i++) {
        cin >> zone1 >> build1 >> zone2 >> build2;
        if (zone1 == zone2) {
            Dmin += abs(build2 - build1);
        } else {
            people.push_back(make_pair(
                (Place){zone1, build1}, 
                (Place){zone2, build2}
            ));
            person.push_back(build1);
            person.push_back(build2);
        }
    }
 
    int M = person.size();
    long long int possibleMin = INF;

    if (M == 0) possibleMin = 0;
    else {
        sort(person.begin(), person.end());
        for (int i = M/2; i <= M/2 + 1; i++) {
            possibleMin = min(possibleMin, cost(person[i]));
        }
    }
 
    cout << possibleMin + Dmin << "\n";
}

Compilation message

bridge.cpp: In function 'long long int cost(long long int)':
bridge.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Place, Place> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int j = 0; j < people.size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 408 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 47 ms 9164 KB Output is correct
13 Correct 73 ms 9712 KB Output is correct
14 Correct 44 ms 8136 KB Output is correct
15 Correct 44 ms 5312 KB Output is correct
16 Correct 48 ms 8608 KB Output is correct
17 Correct 60 ms 10076 KB Output is correct
18 Correct 59 ms 8888 KB Output is correct
19 Correct 69 ms 9400 KB Output is correct
20 Correct 52 ms 9408 KB Output is correct
21 Correct 63 ms 9660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -