답안 #1054157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054157 2024-08-12T07:06:29 Z Harold Palembang Bridges (APIO15_bridge) C++14
0 / 100
0 ms 460 KB
#include<bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    vector<pair<int, int>> a, p;
    int res = 0;
    for(int i = 0; i < n; i++) {
        char c1, c2;
        int a1, a2;
        cin >> c1 >> a1 >> c2 >> a2;
        if(c1 == c2) {
            res += abs(a1-a2);
        }
        else {
            a.push_back({a1, a2});
        }
    }
    sort(a.begin(), a.end());
    for(auto i: a) {
        pair<int, int> cur = {i.first, i.second};
        if(p.empty()) {
            p.push_back(cur);
            continue;
        }
        if(p.back().second >= cur.first) {
            p.back() = {cur.first, p.back().second};
        }
        else {
            p.push_back(cur);
        }
    }
    int i = 0; // point to cur element in a
    int j = 0; // point to element in p
    int cross = 0;
    while(k > 0 && j < p.size()) {
        cross = p[j].second;
        while(i < a.size() && a[i].first <= cross) {
            res += abs(a[i].second-a[i].first);
            i++;
        }
        j++;
        k--;
    }

    while(i < a.size()) {
        res += abs(a[i].second-a[i].first) + 2*abs(cross-a[i].first);
        i++;
    }

    cout << res+a.size() << endl;

    return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while(k > 0 && j < p.size()) {
      |                    ~~^~~~~~~~~~
bridge.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         while(i < a.size() && a[i].first <= cross) {
      |               ~~^~~~~~~~~~
bridge.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     while(i < a.size()) {
      |           ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -