답안 #635178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635178 2022-08-25T15:23:06 Z finn__ Palembang Bridges (APIO15_bridge) C++17
22 / 100
128 ms 5892 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    size_t n, k;
    cin >> k >> n;

    vector<long> home, work;
    vector<long> positions;
    long cost = 0;

    for (size_t i = 0; i < n; i++)
    {
        char p, q;
        long s, t;
        cin >> p >> s >> q >> t;
        if (p != q)
        {
            home.push_back(s);
            work.push_back(t);
            positions.push_back(s);
            positions.push_back(t);
        }
        else
        {
            cost += abs(s - t);
        }
    }

    if (positions.empty())
    {
        cout << cost << '\n';
        return 0;
    }

    sort(positions.begin(), positions.end());
    long median = positions[positions.size() / 2];

    for (size_t i = 0; i < home.size(); i++)
    {
        cost += abs(home[i] - median) + abs(work[i] - median) + 1;
    }

    cout << cost << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 368 KB Output is correct
10 Correct 2 ms 316 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 304 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 68 ms 4328 KB Output is correct
13 Correct 127 ms 5892 KB Output is correct
14 Correct 99 ms 4532 KB Output is correct
15 Correct 67 ms 3644 KB Output is correct
16 Correct 81 ms 5108 KB Output is correct
17 Correct 117 ms 5836 KB Output is correct
18 Correct 108 ms 5500 KB Output is correct
19 Correct 128 ms 5876 KB Output is correct
20 Correct 118 ms 5372 KB Output is correct
21 Correct 104 ms 5644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 300 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 1 ms 304 KB Output isn't correct
4 Halted 0 ms 0 KB -