Submission #1054275

# Submission time Handle Problem Language Result Execution time Memory
1054275 2024-08-12T08:19:59 Z Rojus Palembang Bridges (APIO15_bridge) C++14
22 / 100
2000 ms 12136 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int k, n;
    cin >> k >> n;
    vector<pair<int, int>> v;
    vector<int> sarasas;
    vector<int> taskai;
    set<int> s;
    long long priedas=0;
    for(int i=0; i<n; i++)
    {
        char cg, cd;
        int ig, id;
        cin >> cg >> ig >> cd >> id;
        if(cg!=cd)
        {
            priedas++;
            v.push_back({ig, id});
            sarasas.push_back(ig);
            sarasas.push_back(id);
            if(s.find(ig)==s.end())
            {
                s.insert(ig);
                taskai.push_back(ig);
            }
            if(s.find(id)==s.end())
            {
                s.insert(id);
                taskai.push_back(id);
            }

        }
        else
        {
            priedas+=abs(ig-id);
        }
    }
    sort(sarasas.begin(), sarasas.end());
    if(k==1)
    {
        int tiltas=sarasas.size()/2;
        long long sum=priedas;
        for(int i=0; i<v.size(); i++)
        {
            sum+=abs(v[i].first-sarasas[tiltas])+abs(v[i].second-sarasas[tiltas]);
        }
        cout << sum;
    }
    else
    {
        long long mins=LONG_MAX;
        for(int i=0; i<taskai.size()-1; i++)
        {
            for(int j=i+1; j<taskai.size(); j++)
            {
                long long sum=0;
                for(int k=0; k<v.size(); k++)
                {
                    sum+=min(abs(v[k].first-taskai[i])+abs(v[k].second-taskai[i]), abs(v[k].first-taskai[j])+abs(v[k].second-taskai[j]));
                }
                mins=min(mins, sum);
            }
        }
        mins+=priedas;
        cout << mins;
    }

    return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int i=0; i<v.size(); i++)
      |                      ~^~~~~~~~~
bridge.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int i=0; i<taskai.size()-1; i++)
      |                      ~^~~~~~~~~~~~~~~~
bridge.cpp:59:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for(int j=i+1; j<taskai.size(); j++)
      |                            ~^~~~~~~~~~~~~~
bridge.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 for(int k=0; k<v.size(); k++)
      |                              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 12 ms 2248 KB Output is correct
13 Correct 80 ms 12136 KB Output is correct
14 Correct 33 ms 2432 KB Output is correct
15 Correct 45 ms 7200 KB Output is correct
16 Correct 14 ms 2248 KB Output is correct
17 Correct 57 ms 11948 KB Output is correct
18 Correct 72 ms 12036 KB Output is correct
19 Correct 70 ms 11696 KB Output is correct
20 Correct 19 ms 2244 KB Output is correct
21 Correct 55 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2025 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -