답안 #858003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858003 2023-10-07T09:33:59 Z sofijavelkovska The Potion of Great Power (CEOI20_potion) C++14
17 / 100
3000 ms 4616 KB
#include <bits/stdc++.h>
using namespace std;

const int INF=1e9;

int n, d, u;
vector<int> h, a, b;

void init(int N, int D, int H[])
{
    n=N;
    d=D;
    h.resize(n);
    for (int i=0; i<n; i++)
        h[i]=H[i];

    return;
}

void curseChanges(int U, int A[], int B[])
{
    u=U;
    a.resize(u);
    b.resize(u);
    for (int i=0; i<u; i++)
        a[i]=A[i];
    for (int i=0; i<u; i++)
        b[i]=B[i];

    return;
}

int question(int x, int y, int v)
{
    set<int> xtrust, ytrust;
    for (int i=0; i<v; i++)
    {
        if (a[i]==x)
        {
            if (!xtrust.count(b[i]))
                xtrust.insert(b[i]);
            else
                xtrust.erase(b[i]);
        }
        if (b[i]==x)
        {
            if (!xtrust.count(a[i]))
                xtrust.insert(a[i]);
            else
                xtrust.erase(a[i]);
        }
        if (a[i]==y)
        {
            if (!ytrust.count(b[i]))
                ytrust.insert(b[i]);
            else
                ytrust.erase(b[i]);
        }
        if (b[i]==y)
        {
            if (!ytrust.count(a[i]))
                ytrust.insert(a[i]);
            else
                ytrust.erase(a[i]);
        }
    }
    vector<int> vx, vy;
    for (auto t : xtrust)
        vx.push_back(h[t]);
    for (auto t : ytrust)
        vy.push_back(h[t]);
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    if (vx.empty() || vy.empty())
        return INF;
    int mind=INF;
    int j=0;
    for (int i=0; i<vx.size(); i++)
    {
        while (j<vy.size() && vx[i]>vy[j])
            j=j+1;
        if (j<vy.size())
            mind=min(mind, vy[j]-vx[i]);
        if (j-1>=0)
            mind=min(mind, vx[i]-vy[j-1]);
    }

    return mind;
}

/*int main()
{
    int htemp[]={ 2 , 42 , 1000 , 54 , 68 , 234 };
    init(6, 5, htemp );
    int atemp[]={ 0 , 2 , 3 , 3 , 3 , 1 , 5 , 0 , 3 , 1 , 3 };
    int btemp[]={ 1 , 0 , 4 , 5 , 5 , 3 , 3 , 5 , 0 , 3 , 5 };
    curseChanges(11, atemp, btemp) ;
    while (true)
    {
        int x, y, v;
        cin >> x >> y >> v;
        cout << question(x, y, v) << '\n';
    }

    return 0;
}*/

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i=0; i<vx.size(); i++)
      |                   ~^~~~~~~~~~
potion.cpp:80:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         while (j<vy.size() && vx[i]>vy[j])
      |                ~^~~~~~~~~~
potion.cpp:82:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         if (j<vy.size())
      |             ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 10 ms 1268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3045 ms 4616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3056 ms 4380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 530 ms 608 KB Output is correct
2 Correct 746 ms 856 KB Output is correct
3 Correct 2921 ms 600 KB Output is correct
4 Execution timed out 3082 ms 600 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 10 ms 1268 KB Output is correct
6 Execution timed out 3045 ms 4616 KB Time limit exceeded
7 Halted 0 ms 0 KB -