답안 #971328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971328 2024-04-28T11:21:46 Z socpite Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
 
long long INF = 1e18;
 
vector<int> cp;
 
vector<pair<int, int>> vec;
 
int k, n;
 
int main(){
    cin >> k >> n;
    long long ans = INF;
    long long base = 0;
    for(int i = 0; i < n; i++){
        char t1, t2;
        pair<int, int> p;
        cin >> t1 >> p.first >> t2 >> p.second;
        if(p.first > p.second)swap(p.first, p.second);
        base += p.second - p.first;
        if(t1 != t2) {
            base++;
            vec.push_back(p);
            cp.push_back(p.first);
            cp.push_back(p.second);
        }
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    for(auto x: cp){
        for(auto y: cp){
            long long sum = 0;
            for(auto p: vec){
                if(p.first <= x && x <= p.second)continue;
                if(p.first <= y && y <= p.second)continue;
                sum += min(min(abs(x - p.first), abs(x - p.second)), min(abs(y - p.first), abs(y - p.second)));
            }
            ans = min(ans, sum);
            // cout << x << " " << y << " " << sum << endl;
        }
    }
    cout << base + ans*2;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 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 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -