Submission #1016921

# Submission time Handle Problem Language Result Execution time Memory
1016921 2024-07-08T15:35:28 Z TroySer Palembang Bridges (APIO15_bridge) C++17
8 / 100
2000 ms 6244 KB
#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;

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}
            ));
        }
    }

    int M = people.size();
    long long int possibleMin = INF;
    
    for (int i = 0; i < M; i++) {
        long long int currK = people[i].first.building;
        long long int currMin = 0;
        for (int j = 0; j < M; j++) {
            currMin += abs(people[j].first.building - currK);
            currMin++;
            currMin += abs(people[j].second.building - currK);
        }
        possibleMin = min(currMin, possibleMin);

        currK = people[i].second.building;
        currMin = 0;
        for (int j = 0; j < M; j++) {
            currMin += abs(people[j].first.building - currK);
            currMin++;
            currMin += abs(people[j].second.building - currK);
        }
        possibleMin = min(currMin, possibleMin);
    }

    if (M == 0) possibleMin = 0;

    cout << possibleMin + Dmin << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 516 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 344 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 3 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Execution timed out 2096 ms 6244 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 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 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 344 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 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -