Submission #964309

# Submission time Handle Problem Language Result Execution time Memory
964309 2024-04-16T15:45:05 Z maxFedorchuk Gondola (IOI14_gondola) C++17
60 / 100
26 ms 5124 KB
#include <bits/stdc++.h>
using namespace std;
#include "gondola.h"

int valid(int n, int inputSeq[])
{
    set < int > st;

    int p=0;
    for(int i=0;i<n;i++)
    {
        if(inputSeq[i]<=n)
        {
            p=(n+i-inputSeq[i])%n;
        }

        st.insert(inputSeq[i]);
    }

    if(st.size()!=n)
    {
        return 0;
    }

    for(int i=0;i<n;i++)
    {
        if(inputSeq[i]<=n)
        {
            if((n+i-inputSeq[i])%n!=p)
            {
                return 0;
            }
        }
    }

    return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int ned_to_be[n],in=-1;
    for(int i=0;i<n;i++)
    {
        if(gondolaSeq[i]<=n)
        {
            ned_to_be[i]=gondolaSeq[i];
            in=i;
            break;
        }
    }

    if(in!=-1)
    {
        int nd=ned_to_be[in];
        for(int i=(in+1)%n;i!=in;i=(i+1)%n)
        {
            nd%=n;
            nd++;

            ned_to_be[i]=nd;
        }
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            ned_to_be[i]=i+1;
        }
    }

    map < int , int > mp;

    int mx=0;
    for(int i=0;i<n;i++)
    {
        if(gondolaSeq[i]>mx)
        {
            mx=gondolaSeq[i];
            in=i;
        }

        if(gondolaSeq[i]>n)
        {
            mp[gondolaSeq[i]]=ned_to_be[i];
        }
    }

    int uk=0;
    for(int i=n+1;i<=mx;i++,uk++)
    {
        if(mp.find(i)==mp.end() || i==mx)
        {
            replacementSeq[uk]=ned_to_be[in];
            ned_to_be[in]=i;
        }
        else
        {
            replacementSeq[uk]=mp[i];
        }
    }

    return uk;
}

//----------------------

const long long MOD=1e9+7;

long long binpow(long long a,long long b)
{
    long long rt=1;

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

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

    return rt;
}

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

    set < long long > st;

    for(long long i=0;i<n;i++)
    {
        if(inputSeq[i]>n)
        {
            st.insert(inputSeq[i]);
        }
    }

    long long mun=n,ans=1,k=st.size();
    for(auto u:st)
    {
        //cout<<u<<" "<<k<<" "<<u-mun-1<<"\n";
        ans=(ans*binpow(k,u-mun-1))%MOD;
        k--;
        mun=u;
    }

    if(st.size()==n)
    {
        ans=(ans*n)%MOD;
    }

    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(st.size()!=n)
      |        ~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:155:17: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  155 |     if(st.size()==n)
      |        ~~~~~~~~~^~~
# 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 612 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 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 448 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 2396 KB Output is correct
7 Correct 25 ms 4176 KB Output is correct
8 Correct 14 ms 4300 KB Output is correct
9 Correct 5 ms 1624 KB Output is correct
10 Correct 19 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 8 ms 2356 KB Output is correct
7 Correct 20 ms 4316 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 5 ms 1512 KB Output is correct
10 Correct 18 ms 4956 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 10 ms 2472 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 26 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 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 1 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
11 Correct 11 ms 1372 KB Output is correct
12 Correct 7 ms 1592 KB Output is correct
13 Correct 19 ms 2944 KB Output is correct
14 Correct 7 ms 1368 KB Output is correct
15 Correct 21 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 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 1 ms 604 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 1 ms 344 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 352 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 1 ms 344 KB Output is correct
7 Incorrect 1 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -