Submission #3402799

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int main(){
    int64_t i, j, k;
    int N;
    vector<vector<int64_t>> weight;
    cin >> N;
    for(i=0; i<N; i++){
        int64_t a, b;
        scanf("%lld %lld", &a, &b);
        weight.push_back({a, 0LL, i});
        weight.push_back({b, 1LL, i});
    }
    sort(weight.begin(), weight.end());
    int use_side[2] = {0, 0};
    bool dub = false;
    bool use_num[100000];
    for(i=0; i<N; i++) use_num[i] = false;

    int64_t ans = 0;
    for(i=0; i<N; i++){
        auto v = weight[i];
        ans += v[0];
        use_side[v[1]]++;
        if(use_num[v[2]]) dub = true;
        use_num[v[2]] = true;
    }

    if(use_side[0]>0 && use_side[1]>0 && !dub){
        int64_t loss;
        if(weight[N-1][2] == weight[N][2] && use_side[weight[N-1][1]] > 1){
            loss = min(weight[N+1][0] - weight[N-1][0], weight[N][0] - weight[N-2][0]);
        }else{
            loss = weight[N][0] - weight[N-1][0];
        }
        ans += loss;
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Min Cost Cycle
User betrue12
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1080 Byte
Status
Exec Time 89 ms
Memory 12464 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:11:34: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t* {aka long int*}’ [-Wformat=]
         scanf("%lld %lld", &a, &b);
                                  ^
./Main.cpp:11:34: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘int64_t* {aka long int*}’ [-Wformat=]
./Main.cpp:11:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &a, &b);
                                   ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 700 / 700 sample-01.txt, sample-02.txt, sample-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, subtask01-01.txt, subtask01-02.txt, subtask01-03.txt, subtask01-04.txt, subtask01-05.txt, subtask01-06.txt, subtask01-07.txt, subtask01-08.txt, subtask01-09.txt, subtask01-10.txt, subtask01-11.txt, subtask01-12.txt, subtask01-13.txt, subtask01-14.txt, subtask01-15.txt, subtask01-16.txt, subtask01-17.txt, subtask01-18.txt, subtask01-19.txt, subtask01-20.txt, subtask01-21.txt, subtask01-22.txt, subtask01-23.txt, subtask01-24.txt, subtask01-25.txt
Case Name Status Exec Time Memory
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
subtask01-01.txt 1 ms 256 KB
subtask01-02.txt 59 ms 11056 KB
subtask01-03.txt 81 ms 11696 KB
subtask01-04.txt 2 ms 384 KB
subtask01-05.txt 52 ms 7344 KB
subtask01-06.txt 56 ms 11696 KB
subtask01-07.txt 81 ms 11692 KB
subtask01-08.txt 76 ms 11948 KB
subtask01-09.txt 50 ms 7088 KB
subtask01-10.txt 53 ms 7472 KB
subtask01-11.txt 69 ms 11568 KB
subtask01-12.txt 73 ms 11696 KB
subtask01-13.txt 40 ms 5680 KB
subtask01-14.txt 87 ms 12208 KB
subtask01-15.txt 85 ms 12460 KB
subtask01-16.txt 86 ms 12204 KB
subtask01-17.txt 85 ms 12464 KB
subtask01-18.txt 85 ms 11952 KB
subtask01-19.txt 89 ms 12332 KB
subtask01-20.txt 86 ms 11948 KB
subtask01-21.txt 86 ms 12460 KB
subtask01-22.txt 85 ms 12208 KB
subtask01-23.txt 85 ms 11820 KB
subtask01-24.txt 86 ms 12076 KB
subtask01-25.txt 86 ms 11948 KB