제출 #104900

#제출 시각아이디문제언어결과실행 시간메모리
104900daili케이크 (CEOI14_cake)C++14
0 / 100
2094 ms4600 KiB
#include <bits/stdc++.h>

using namespace std;

int sim(vector<int>& deli , int a, int b)
{
    int eaten = 1;
    a--; b--;

    if (a == b)
    {
        return 0;
    }

    int currL = a;
    int currR = a;

    while(true)
    {
        int L = 99999999;
        if (currL > 0)
        {
            L = deli[currL - 1];
        }

        int R = 99999999;
        if (currR < deli.size() - 1)
        {
            R = deli[currR + 1];
        }

        if (L < R)
        {
            if (currL - 1 == b)
            {
                return eaten;
            }
            currL--;
        }
        else
        {
            if (currR + 1 == b)
            {
                return eaten;
            }
            currR++;
        }
        eaten++;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, a;
    cin >> n >> a;

    vector<pair<int,int>> copy1;
    vector<int> deli;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        deli.push_back(x);
        copy1.push_back({x, i});
    }

    sort(copy1.begin(), copy1.end());
    set<int> top10s;
    vector<int> top10;
    for (int i = copy1.size() - 1; i >= 0 && i >= n-10; i--)
    {
        top10.push_back(copy1[i].second);
        top10s.insert(copy1[i].second);
    }

    int q;
    cin >> q;

    while(q--)
    {
        char type;
        cin >> type;

        if (type == 'E')
        {
            int id, e;
            cin >> id >> e;
            e--; id--;
            for (int i = 0; i < e; i++)
            {
                deli[top10[i]]++;
            }
            int cnt = 1;
            for (int i = top10.size()-1; i > e+1; i--)
            {
                if (top10[i-1] == id) cnt++;
                top10[i] = top10[i-cnt];
            }

            top10[e] = id;
            deli[id] = deli[top10[e+1]] + 1;
        }
        else
        {
            int b;
            cin >> b;
            int res = sim(deli, a, b);
            cout << res << "\n";
        }
    }


}

컴파일 시 표준 에러 (stderr) 메시지

cake.cpp: In function 'int sim(std::vector<int>&, int, int)':
cake.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (currR < deli.size() - 1)
             ~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...