답안 #1054212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054212 2024-08-12T07:40:10 Z FaustasK Palembang Bridges (APIO15_bridge) C++14
31 / 100
2000 ms 4804 KB
#include <bits/stdc++.h>

using namespace std;

struct gyventojas
{
    char p;
    int s;
    char q;
    int t;
};

const int maxn = 100000;

int k, n;
gyventojas M[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> k >> n;
    long long A_puse = 0;
    long long B_puse = 0;
    vector <int> reikalingi;
    vector <int> nereikalingi;
    vector <int> medianai;
    for(int i = 0; i<n; i++)
    {
        cin >> M[i].p >> M[i].s >> M[i].q >> M[i].t;
        if(M[i].p != M[i].q)
        {
            reikalingi.push_back(i);
            medianai.push_back(M[i].s);
            medianai.push_back(M[i].t);
            if(M[i].p == 'A' && M[i].q == 'B')
            {
                A_puse += M[i].s;
                B_puse += M[i].t;
            }
            else
            {
                A_puse += M[i].t;
                B_puse += M[i].s;
            }
        }
        else nereikalingi.push_back(i);
    }
    int kiek = reikalingi.size();
    long long ats = 0;
    if(kiek>0)
    {
        /*long long suma = A_puse + B_puse;
        double liekana1 = suma%2;
        //cout << liekana1 << endl;
        liekana1/=2;
        suma/=2;
        //cout << suma << endl;
        //cout << liekana1 << endl;
        double liekana2 = suma%kiek;
        //cout << liekana2 << endl;
        liekana2 += liekana1;
        //cout << liekana2 << endl;
        liekana2/=kiek;
        //cout << liekana2 << endl;
        suma/=kiek;
        //cout << suma << endl;
        double dsuma = suma + liekana2;
        //cout << dsuma << endl;
        int tiltas = round(dsuma);
        //cout << ats;*/
        if(k == 1)
        {
            sort(medianai.begin(), medianai.end());
            int tiltas = medianai[medianai.size()/2];
            for(int i = 0; i<reikalingi.size(); i++)
            {
                int j = reikalingi[i];
                ats += abs(M[j].s - tiltas) + abs(M[j].t - tiltas);
            }
        }
        else
        {
            ats = 1000000000000000;
            for(int i = 0; i<medianai.size(); i++)
            {
                for(int j = 0; j<medianai.size(); j++)
                {
                    if(i == j) continue;
                    int tiltas1 = medianai[i];
                    int tiltas2 = medianai[j];
                    long long maz_ats = 0;
                    for(int f = 0; f<reikalingi.size(); f++)
                    {
                        int x = reikalingi[f];
                        int a1 = abs(M[x].s - tiltas1) + abs(M[x].t - tiltas1);
                        int a2 = abs(M[x].s - tiltas2) + abs(M[x].t - tiltas2);
                        maz_ats += min(a1, a2);
                    }
                    ats = min(ats, maz_ats);
                }
            }
        }
    }
    for(int i = 0; i<nereikalingi.size(); i++)
    {
        int j = nereikalingi[i];
        ats += abs(M[j].s - M[j].t);
    }
    cout << ats + reikalingi.size();
    return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:75:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             for(int i = 0; i<reikalingi.size(); i++)
      |                            ~^~~~~~~~~~~~~~~~~~
bridge.cpp:84:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int i = 0; i<medianai.size(); i++)
      |                            ~^~~~~~~~~~~~~~~~
bridge.cpp:86:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                 for(int j = 0; j<medianai.size(); j++)
      |                                ~^~~~~~~~~~~~~~~~
bridge.cpp:92:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |                     for(int f = 0; f<reikalingi.size(); f++)
      |                                    ~^~~~~~~~~~~~~~~~~~
bridge.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for(int i = 0; i<nereikalingi.size(); i++)
      |                    ~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 396 KB Output is correct
11 Correct 0 ms 476 KB Output is correct
12 Correct 12 ms 4044 KB Output is correct
13 Correct 25 ms 4804 KB Output is correct
14 Correct 18 ms 3784 KB Output is correct
15 Correct 16 ms 3336 KB Output is correct
16 Correct 15 ms 4288 KB Output is correct
17 Correct 19 ms 4796 KB Output is correct
18 Correct 20 ms 4616 KB Output is correct
19 Correct 24 ms 4804 KB Output is correct
20 Correct 16 ms 4660 KB Output is correct
21 Correct 21 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 348 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 380 KB Output is correct
7 Correct 11 ms 468 KB Output is correct
8 Correct 11 ms 348 KB Output is correct
9 Correct 10 ms 348 KB Output is correct
10 Correct 10 ms 468 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 10 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 468 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 11 ms 348 KB Output is correct
8 Correct 13 ms 348 KB Output is correct
9 Correct 10 ms 468 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 10 ms 476 KB Output is correct
12 Correct 10 ms 344 KB Output is correct
13 Execution timed out 2075 ms 348 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 468 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 11 ms 468 KB Output is correct
8 Correct 10 ms 472 KB Output is correct
9 Correct 11 ms 344 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 10 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Execution timed out 2092 ms 348 KB Time limit exceeded
14 Halted 0 ms 0 KB -