답안 #660784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660784 2022-11-23T08:42:08 Z alexander707070 Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
#define MAXN 100007
using namespace std;

const long long inf=1e15;

struct person{
    char s;
    int from;
    char t;
    int to;
}a[MAXN];

struct event{
    int pos;
    int id,type;

    inline friend bool operator < (event fr,event sc){
        return fr.pos<sc.pos;
    }
};

int n,k,br[MAXN];
char type;
long long sum,last,lt,rt,cntl,cntr,ans;
vector<event> v;

void solve1(){
    ans=inf;

    last=v[v.size()-1].pos;
    for(int i=v.size()-1;i>=0;i--){
        rt+=(last-v[i].pos)*cntr;
        br[v[i].id]++;
        if(br[v[i].id]==2){
            cntr+=2;
            rt+=a[v[i].id].from+a[v[i].id].to-2*v[i].pos;
            rt++;
        }
        last=v[i].pos;
    }

    return;

    last=v[0].pos;
    for(int i=0;i<v.size();i++){
        lt+=(v[i].pos-last)*cntl;
        rt-=(v[i].pos-last)*cntr;

        br[v[i].id]--;
        if(br[v[i].id]==1){
            rt-=abs(a[v[i].id].from-a[v[i].id].to); cntr-=2; rt--;
            sum+=abs(a[v[i].id].from-a[v[i].id].to)+1;
        }else{
            sum-=abs(a[v[i].id].from-a[v[i].id].to)+1;
            lt+=abs(a[v[i].id].from-a[v[i].id].to); cntl+=2;
            lt++;
        }

        ans=min(ans,lt+rt+sum);
        last=v[i].pos;
    }

    cout<<ans<<"\n";
}

void solve2(){

}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>k>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].s>>a[i].from>>a[i].t>>a[i].to;
        if(a[i].s==a[i].t){
            sum+=abs(a[i].from-a[i].to);
        }else{
            v.push_back({a[i].from,i,1});
            v.push_back({a[i].to,i,2});
        }
    }

    sort(v.begin(),v.end());

    if(k==1){
        solve1();
    }else{
        solve2();
    }

    return 0;
}

Compilation message

bridge.cpp: In function 'void solve1()':
bridge.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -