Submission #1054171

# Submission time Handle Problem Language Result Execution time Memory
1054171 2024-08-12T07:13:33 Z Mokocraft Palembang Bridges (APIO15_bridge) C++14
22 / 100
59 ms 4408 KB
#include <iostream>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <vector>
#include <cmath>

int main()
{
    //freopen("duotaA.txt", "r", stdin);

    int K, N;
    std::cin >> K >> N;

    long long extra = 0;
    std::vector<std::pair<int, int>> ranges;
    for(int i = 0; i < N; i++)
    {
        int ai, bi;
        char ac, bc;
        std::cin >> ac >> ai >> bc >> bi;

        if(ai > bi)
            std::swap(ai, bi);

        if(ac == bc)
            extra += bi - ai;
        else
            ranges.push_back(std::make_pair(ai, bi));
    }

    N = ranges.size();

    if(N == 0)
    {
        std::cout << extra;
        return 0;
    }

    if(K == 1)
    {
        long long dist = 0;
        int nums[N*2];
        for(int i = 0; i < N; i++)
        {
            nums[i*2] = ranges[i].first;
            nums[i*2+1] = ranges[i].second;
        }

        std::sort(nums, nums + N*2);

        int point = nums[N];

        for(int i = 0; i < N; i++)
        {
            if(point >= ranges[i].first && point <= ranges[i].second)
                dist += 1 + ranges[i].second - ranges[i].first;
            else dist += 1 + ranges[i].second - ranges[i].first + 2 * std::min(std::abs(ranges[i].second - point), std::abs(ranges[i].first - point));
        }

        std::cout << dist + extra;
    }
    

    return 0;
}
# 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 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 468 KB Output is correct
11 Correct 1 ms 348 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 0 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 0 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 448 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 24 ms 2700 KB Output is correct
13 Correct 59 ms 4408 KB Output is correct
14 Correct 35 ms 3016 KB Output is correct
15 Correct 33 ms 2712 KB Output is correct
16 Correct 39 ms 3764 KB Output is correct
17 Correct 48 ms 4296 KB Output is correct
18 Correct 54 ms 4036 KB Output is correct
19 Correct 55 ms 4292 KB Output is correct
20 Correct 42 ms 3784 KB Output is correct
21 Correct 50 ms 4040 KB Output is correct
# 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 -
# 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 -