제출 #1282833

#제출 시각아이디문제언어결과실행 시간메모리
1282833ghammazhassanPalembang Bridges (APIO15_bridge)C++20
0 / 100
2 ms580 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=1e9+7;
const int inf = 1e9;
const int LOG=17;
const int N=1e5+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
void solve()
{       
    cin >> k >> n;
    vector<pair<int,int>>a,b;
    int f=0;
    for (int i=0;i<n;i++){
        char s,t;
        cin >> s >> x >> t >> y;
        if (s==t){
            f+=abs(x-y);
        }
        else{
            a.push_back({x,y});
            b.push_back({y,x});
        }
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    n=a.size();
    if (!n){
        cout << f << endl;
        return;
    }
    int u=a[0].fi;
    int j=0;
    c=0;
    int d=0;
    for (int i=0;i<n;i++){
        d++;
        while (b[j].fi<a[i].fi){
            d--;
            j++;
        }
        if (d>c){
            c=d;
            u=b[j].fi;
        }
    }
    c=0;
    for (auto i:a){
        c+=abs(i.fi-u)+abs(i.se-u)+1;
    }
    cout << c+f << endl;
}
signed main()    
{

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed << setprecision(9);
    srand(time(0));
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
        solve();
        q++;
    }
} 
#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...