Submission #1019849

# Submission time Handle Problem Language Result Execution time Memory
1019849 2024-07-11T09:48:16 Z NValchanov Gondola (IOI14_gondola) C++17
100 / 100
48 ms 6612 KB
#include <bits/stdc++.h>
#include "gondola.h"

#define endl '\n'

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 9;

int valid(int n, int a[])
{
    set < int > cnt;

    int min_idx = 0;

    for(int i = 1; i < n; i++)
    {
        if(a[i] < a[min_idx])
            min_idx = i;

        if(cnt.count(a[i]))
            return 0;
        
        cnt.insert(a[i]);
    }

    vector < int > order;

    for(int i = min_idx; i < n; i++)
    {
        order.push_back(a[i]);
    }
    for(int i = 0; i < min_idx; i++)
    {
        order.push_back(a[i]);
    }

    for(int i = 1; i < n; i++)
    {
        if(order[i] <= n && order[i] - order[0] != i)
            return 0;
    }

    return 1;
}

int replacement(int n, int a[], int ans[])
{
    int min_idx = 0;
    int maxel = 0;

    for(int i = 0; i < n; i++)
    {
        if(a[i] < a[min_idx])
            min_idx = i;
        
        maxel = max(maxel, a[i]);
    }

    vector < int > order;

    for(int i = min_idx; i < n; i++)
    {
        order.push_back(a[i]);
    }
    for(int i = 0; i < min_idx; i++)
    {
        order.push_back(a[i]);
    }

    vector < pair < int, int > > broken;

    for(int i = 0; i < n; i++)
    {
        if(order[i] > n)
            broken.push_back({order[i], i});
    }

    sort(broken.begin(), broken.end());

    if(order.front() > n)
        order.front() = 1;

    for(int i = 1; i < n; i++)
    {
        if(order[i - 1] == n)
        {
            order[i] = 1;
        }
        else
        {
            order[i] = order[i - 1] + 1;
        }
    }

    int last = n;
    int pos = 0;

    for(pair < int, int > p : broken)
    {
        int val = p.first;
        int idx = p.second;

        while(last < val)
        {
            ans[pos++] = order[idx];
            order[idx] = ++last;
        }
    }

    return maxel - n;
}

ll binpow(ll a, ll b)
{
    ll result = 1;

    while(b)
    {
        if(b & 1)
            result = (result * a) % MOD;

        a = (a * a) % MOD;
        b /= 2;
    }

    return result;
}

int countReplacement(int n, int a[])
{
    if(!valid(n, a))
        return 0;

    vector < ll > broken;

    for(int i = 0; i < n; i++)
    {
        if(a[i] > n)
            broken.push_back(a[i]);
    }

    sort(broken.begin(), broken.end());

    int sz = broken.size();
    int last = n;
    ll ans;

    if(sz == n) ans = n;
    else ans = 1;

    for(int i = 0; i < sz; i++)
    {
        ans = ans * binpow(sz - i, broken[i] - last - 1) % MOD;
        last = broken[i];
    }

    return ans;
}
# 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2648 KB Output is correct
7 Correct 6 ms 600 KB Output is correct
8 Correct 19 ms 4492 KB Output is correct
9 Correct 6 ms 1624 KB Output is correct
10 Correct 25 ms 5268 KB Output is correct
# 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 11 ms 2648 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 19 ms 4512 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 25 ms 5080 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 13 ms 2452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 31 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 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 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 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
# 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 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 1240 KB Output is correct
12 Correct 6 ms 1240 KB Output is correct
13 Correct 9 ms 1256 KB Output is correct
14 Correct 6 ms 1360 KB Output is correct
15 Correct 13 ms 2180 KB Output is correct
# 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 344 KB Output is correct
# 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 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 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 0 ms 600 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 348 KB Output is correct
9 Correct 33 ms 5080 KB Output is correct
10 Correct 24 ms 4176 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 11 ms 2248 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 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 34 ms 5068 KB Output is correct
10 Correct 27 ms 4188 KB Output is correct
11 Correct 9 ms 2136 KB Output is correct
12 Correct 12 ms 2140 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 40 ms 5940 KB Output is correct
15 Correct 48 ms 6612 KB Output is correct
16 Correct 7 ms 1628 KB Output is correct
17 Correct 29 ms 4660 KB Output is correct
18 Correct 15 ms 2908 KB Output is correct