Submission #1017593

# Submission time Handle Problem Language Result Execution time Memory
1017593 2024-07-09T09:01:31 Z Ice_man Gondola (IOI14_gondola) C++14
100 / 100
47 ms 6420 KB
/**
 ____    ____    ____    __________________    ____    ____    ____
||I ||  ||c ||  ||e ||  ||                ||  ||M ||  ||a ||  ||n ||
||__||  ||__||  ||__||  ||________________||  ||__||  ||__||  ||__||
|/__\|  |/__\|  |/__\|  |/________________\|  |/__\|  |/__\|  |/__\|

*/

#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <queue>
#include <map>

#include "gondola.h"

#define maxn 1005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define mod 1000000009
#define control cout<<"passed"<<endl;

using namespace std;


typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double ld;


std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}




int valid(int n, int a[])
{
    map <int , int> br;
    int minn = INF , idx;

    for(int i = 0; i < n; i++)
    {
        if(minn > a[i])
        {
            minn = a[i];
            idx = i;
        }

        br[a[i]]++;
        if(br[a[i]] > 1)
            return false;
    }

    if(minn > n)
        return true;

    int curr = minn + 1;

    for(int i = idx + 1; i % n != idx; i++)
    {
        if(a[i % n] <= n && a[i % n] != curr)
            return false;
        curr++;
    }

    return true;
}




int replacement(int n, int a[], int r[])
{

    int idx = 0;
    int delta = INF;

    vector <pii> v;
    for(int i = 0; i < n; i++)
    {
        if(a[i] <= n && a[i] < delta)
        {
            delta = a[i];
            idx = i;
        }

        if(a[i] > n)
            v.push_back({a[i] , i});
    }

    if(delta == INF)
        delta = 1;
    sort(v.begin() , v.end());

    int next = n + 1 , curr = 0;
    int old;
    for(auto& e : v)
    {
        if(e.Y < idx)
            old = n - idx + e.Y + delta;
        else
            old = e.Y - idx + delta;
        old %= n;
        if(old == 0)
            old = n;

        r[curr] = old;
        curr++;

        while(next != e.X)
        {
            r[curr] = next;
            next++;
            curr++;
        }

        next = e.X + 1;
    }

    return curr;
}



ll power(ll base , ll p)
{
    ll ans = 1;

    while(p != 0)
    {
        if(p % 2 == 1)
            ans *= base , ans %= mod;

        base *= base;
        base %= mod;

        p /= 2;
    }

    return ans;
}


int countReplacement(int n, int a[])
{
    map <int , int> br;
    int minn = INF , maxx = -INF;
    int idx , shit = 0;

    vector <int> v;

    for(int i = 0; i < n; i++)
    {
        if(minn > a[i])
        {
            minn = a[i];
            idx = i;
        }

        br[a[i]]++;
        if(br[a[i]] > 1)
            return 0;

        maxx = max(maxx , a[i]);

        if(a[i] > n)
        {
            shit++;
            v.pb(a[i]);
        }
    }

    int curr = minn + 1;
    for(int i = idx + 1; i % n != idx; i++)
    {
        if(a[i % n] <= n && a[i % n] != curr)
            return false;
        curr++;
    }

    ll ans = 1;
    int old = n;

    sort(v.begin() , v.end());
    for(int& e : v)
    {
        ans *= power(shit , e - old - 1);
        ans %= mod;

        shit--;
        old = e;
    }

    if(minn > n)
        ans *= n , ans %= mod;

    return ans;
}

















/**int main()
{

#ifdef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ///startT = std::chrono::high_resolution_clock::now();





    return 0;
}
*/

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:58:22: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     int minn = INF , idx;
      |                      ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:193:13: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  193 |     for(int i = idx + 1; i % n != idx; i++)
      |             ^
# 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 18 ms 3924 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 22 ms 4532 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 9 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 18 ms 3928 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 24 ms 4544 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2140 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 33 ms 4700 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 344 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 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 1 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 448 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 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 5 ms 1172 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 8 ms 1484 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 12 ms 2388 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
# 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 1 ms 348 KB Output is correct
5 Correct 0 ms 444 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 0 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 0 ms 444 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 36 ms 5024 KB Output is correct
10 Correct 25 ms 4056 KB Output is correct
11 Correct 11 ms 1628 KB Output is correct
12 Correct 11 ms 2000 KB Output is correct
13 Correct 3 ms 600 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 344 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 33 ms 4852 KB Output is correct
10 Correct 31 ms 4060 KB Output is correct
11 Correct 9 ms 1628 KB Output is correct
12 Correct 12 ms 2100 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 40 ms 5732 KB Output is correct
15 Correct 47 ms 6420 KB Output is correct
16 Correct 7 ms 1540 KB Output is correct
17 Correct 30 ms 4568 KB Output is correct
18 Correct 16 ms 2652 KB Output is correct