답안 #681501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681501 2023-01-13T08:11:41 Z ansgar Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 356 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vc>
#define vvb vector<vb>z
#define si set<int>
#define mii map<int,int>

const int mod=1e9+7;
const int N=2e5+1;
const int LN=LLONG_MAX/10;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int k,n;
    cin>>k>>n;
    int ans=0;
    vi A,B;
    for(int i=0;i<n;i++){
        char e1,e2;
        int p1,p2;
        cin>>e1>>p1>>e2>>p2;
        if(e1==e2){
            ans+=abs(p1-p2);
        }
        else{
            if(e1=='A'){
                A.push_back(p1);
                B.push_back(p2);
            }
            else{
                A.push_back(p2);
                B.push_back(p1);
            }
        }
    }
    int sol=LN;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    if(k==1){
        int aftA=A.size();
        int aftB=B.size();
        int befA=0,befB=0;
        int cA=0,cB=0;
        for(int i : A)cA+=i;
        for(int i : B)cB+=i;
        int p1=0,p2=0;
        for(int i=0;i<n;i++){
            //cout<<cA+cB<<endl;
            sol=min(sol,cA+cB);
            while(p1<A.size() and A[p1]==i){
                aftA--;
                befA++;
                p1++;
            }
            while(p2<B.size() and B[p2]==i){
                aftB--;
                befB++;
                p2++;
            }
            cA-=aftA;
            cA+=befA;
            cB-=aftB;
            cB+=befB;
        }
        //cout<<cA+cB<<endl;
        sol=min(sol,cA+cB);
    }
    else{

    }
    cout<<ans+sol+A.size();
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:59:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             while(p1<A.size() and A[p1]==i){
      |                   ~~^~~~~~~~~
bridge.cpp:64:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             while(p2<B.size() and B[p2]==i){
      |                   ~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 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 324 KB Output isn't correct
2 Halted 0 ms 0 KB -