답안 #1054231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054231 2024-08-12T07:51:17 Z unnick Palembang Bridges (APIO15_bridge) C++14
22 / 100
62 ms 1608 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;

int main() {
    int k, n;
    cin >> k >> n;
    if (k != 1) {
        vector<int> as;
        vector<int> ae;
        vector<int> a;
        ll sum = 0;

        for (int i = 0; i < n; i++) {
            char sa, sb;
            int ia, ib;
            cin >> sa >> ia >> sb >> ib;
            if (sa == sb) {
                sum += abs(ia-ib);
                continue;
            }
            as.push_back(ia);
            ae.push_back(ib);
            a.push_back(ia);
            a.push_back(ib);
            sum += 1;
        }
        ll bs = 0x7FFFFFFFFFFFFFFFll;
        for (auto p1 : a) {
            for (auto p2 : a) {
                ll s = 0;
                for (int i = 0; i < as.size(); i++) {
                    s += min(abs(as[i]-p1) + abs(ae[i]-p1), abs(as[i]-p2) + abs(ae[i]-p2));
                }
                bs = min(bs, s);
            }
        }

        sum += bs;

        cout << sum << "\n";

        return 0;
    }

    vector<int> a;
    ll sum = 0;

    for (int i = 0; i < n; i++) {
        char sa, sb;
        int ia, ib;
        cin >> sa >> ia >> sb >> ib;
        if (sa == sb) {
            sum += abs(ia-ib);
            continue;
        }
        a.push_back(ia);
        a.push_back(ib);
        sum += 1;
    }

    sort(a.begin(), a.end());
    int p = a[a.size() / 2];

    for (auto v : a) {
        sum += abs(v-p);
    }

    cout << sum << "\n";
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:36:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 for (int i = 0; i < as.size(); i++) {
      |                                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 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 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 24 ms 1608 KB Output is correct
13 Correct 62 ms 1484 KB Output is correct
14 Correct 38 ms 1568 KB Output is correct
15 Correct 44 ms 1076 KB Output is correct
16 Correct 39 ms 1544 KB Output is correct
17 Correct 58 ms 1456 KB Output is correct
18 Correct 55 ms 1480 KB Output is correct
19 Correct 59 ms 1468 KB Output is correct
20 Correct 42 ms 1492 KB Output is correct
21 Correct 50 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -