Submission #997372

# Submission time Handle Problem Language Result Execution time Memory
997372 2024-06-12T07:56:03 Z doducanh Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;
#define ii pair<int,int>
const int maxn=1e5+7;
struct nguoi
{
    int xo,yo,xt,yt;
};
nguoi a[maxn];
int k,n;
main()
{
    cin>>k>>n;
    vector<ii>v;
    vector<int>tmp;
    long long delt=0;
    for(int i=1;i<=n;i++){
        char xo,xt;
        cin>>xo>>a[i].yo>>xt>>a[i].yt;
        a[i].xo=(xo=='B');
        a[i].xt=(xt=='B');

        if(xo==xt){
            delt+=abs(a[i].yt-a[i].yo);
        }
        else{
            tmp.push_back(a[i].yo);
            tmp.push_back(a[i].yt);
            v.push_back({a[i].yo,a[i].yt});
        }
    }
    long long ans=LLONG_MAX;
    sort(tmp.begin(),tmp.end());
    tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
    int to=tmp[tmp.size()/2];
    long long s=0ll;
    for(auto [x,y]:v){
        s=s+((abs(x-to)+abs(y-to))+1);
    }
    ans=min(ans,s);
    if(tmp.size()/2-1>=0){
        to=tmp[tmp.size()/2-1];
        long long s=0ll;
        for(auto [x,y]:v)
        {
            s=s+((abs(x-to)+abs(y-to))+1);
        }
        ans=min(ans,s);
    }
    if(tmp.size()/2+1<tmp.size()){
        to=tmp[tmp.size()/2+1];
        long long s=0ll;
        for(auto [x,y]:v)
        {
            s=s+((abs(x-to)+abs(y-to))+1);
        }
        ans=min(ans,s);
    }
    cout<<ans+delt;
    return 0;
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/

Compilation message

bridge.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
bridge.cpp: In function 'int main()':
bridge.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for(auto [x,y]:v){
      |              ^
bridge.cpp:45:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |         for(auto [x,y]:v)
      |                  ^
bridge.cpp:54:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |         for(auto [x,y]:v)
      |                  ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -