답안 #850144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850144 2023-09-15T21:12:06 Z Qwesz Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 356 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;

ll k, n, dis = 0, lef = 0, rig = 0, out = 0;
vector<pair<int, int>> vec;

int main(){
    cin >> k >> n;
    for(int i = 0; i < n; i++){
        char a, b; int x, y;
        cin >> a >> x >> b >> y;
        if(a == b) dis += abs(x - y);
        else{
            dis += abs(x - y) + 1;
            vec.push_back({min(x, y), 0});
            vec.push_back({max(x, y), 1});
            rig += min(x, y);
        }
    }
    sort(vec.begin(), vec.end());
    //cout << dis << " " << rig << endl;
    out = dis + 2 * rig;
    for(int i = 0; i < vec.size(); i++){
        if(vec[i].second == 0) rig -= vec[i].first;
        if(vec[i].second == 1) lef += vec[i].first;
        out = min(out, dis + 2 * abs(rig - lef));
        //cout << out << " " << lef << " " << rig << endl;
    }
    cout << out << endl;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:27: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]
   27 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 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 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -