제출 #311453

#제출 시각아이디문제언어결과실행 시간메모리
311453IgorI식물 비교 (IOI20_plants)C++17
14 / 100
4059 ms8824 KiB
#include <bits/stdc++.h>

using namespace std;

int c;

const int N = 500000;

int H[N];

void call(int i, int k, int n, vector<int> &r, vector<int> &h1)
{
    for (int j = i - 1; j > i - k; j--)
    {
        int id = (j + n) % n;
        if (r[id] == 0 && h1[id] == 0)
        {
            call(id, k, n, r, h1);
        }
    }
    h1[i] = c--;
    for (int j = i - 1; j > i - k; j--)
    {
        int id = (j + n) % n;
        r[id]--;
    }
}

void init(int k, vector<int> r)
{
    int n = r.size();
    vector<int> h1(n);
    c = n;
    int t = 1;
    while (t)
    {
        t = 0;
        for (int i = 0; i < n; i++)
        {
            if (r[i] == 0 && h1[i] == 0)
            {
                call(i, k, n, r, h1);
                t = 1;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        H[i] = h1[i];
    }
}

int compare_plants(int x, int y)
{
    if (H[x] > H[y]) return 1;
    return -1;
}

#ifdef LOCAL
int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> r(n);
    for (int i = 0; i < n; i++) cin >> r[i];
    init(k, r);
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        cout << compare_plants(x, y) << endl;
    }
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...