제출 #1343878

#제출 시각아이디문제언어결과실행 시간메모리
1343878ZeroPalembang Bridges (APIO15_bridge)C++20
0 / 100
1 ms344 KiB

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pi pair<int,int>


signed main(){
    cin.tie(0)->sync_with_stdio(0);
    
    int k, n; cin >> k >> n;

    int cn = 0, s = 0;
    vector<int> x,y;

    for(int i=0; i < n; i ++){
        char a,b; int a1, b1; cin >> a >> a1 >> b >> b1;
        if(a == b) s += abs(a1 - b1);
        else x.pb(a1), y.pb(b1), cn ++;
    }

    int mn = INT_MAX;

    for(int i=0; i < cn; i ++){
        for(int j=i+1; j < cn; j ++){
            int cr = s;
            for(int h = 0; h < cn; h ++){
                int t = min({abs(x[h] - x[i]) + abs(y[h] - x[i]) + 1, abs(x[h] - x[j]) + abs(y[h] - x[j]) + 1, abs(x[h] - y[i]) + abs(y[h] - y[i]) + 1, abs(x[h] - y[j]) + abs(y[h] - y[j]) + 1});
                cr += t;
            }
            mn = min(mn, cr);
        }
    }

    cout << mn;


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...