Submission #1017432

# Submission time Handle Problem Language Result Execution time Memory
1017432 2024-07-09T07:55:43 Z simona1230 Gondola (IOI14_gondola) C++17
60 / 100
38 ms 7316 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

long long mult(long long x,long long p)
{
    if(p==0)return 1;
    if(p==1)return x;
    long long half=mult(x,p/2);
    if(p%2==0)return (half*half)%mod;
    return (((half*half)%mod)*x)%mod;
}
int n;
long long a[100001];
map<long long,long long> mp;
bool check()
{
    mp.clear();
    long long idx=-1;
    for(int i=0;i<n;i++)
    {
        if(mp[a[i]])return 0;
        mp[a[i]]++;
        if(a[i]<=n)
        {
            idx=i;
        }
    }
    if(idx==-1)return 1;

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

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

int valid(int N, int inputSeq[])
{
    n=N;
    for(int i=0;i<n;i++)
        a[i]=inputSeq[i];
        //cout<<check()<<endl;
    return check();
}

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


int req[100001];
void needed()
{
    int idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=n)
        {
            idx=i;
        }
    }
    if(idx==-1)
    {
        for(int i=0;i<n;i++)
            req[i]=i+1;
        return;
    }

    int curr=a[idx];
    for(int i=idx;i<n;i++)
    {
        req[i]=curr;
        curr++;
        if(curr==n+1)curr=1;
    }

    for(int i=0;i<idx;i++)
    {
        req[i]=curr;
        curr++;
        if(curr==n+1)curr=1;
    }
}

bool cmp(int i,int j)
{
    return a[i]<a[j];
}

int replacement(int N, int gondolaSeq[], int replacementSeq[])
{
    n=N;
    for(int i=0;i<n;i++)
        a[i]=gondolaSeq[i];
    needed();
    vector<int> v;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=req[i])v.push_back(i);
    }
    sort(v.begin(),v.end(),cmp);

    /*for(int i=0;i<n;i++)
        cout<<req[i]<<" ";
    cout<<endl;*/
    int all=n+1;
    int cnt=0;
    for(int i=0;i<v.size();i++)
    {
        int idx=v[i];
        //cout<<req[idx]<<endl;
        while(req[idx]!=a[idx])
        {
            replacementSeq[cnt++]=req[idx];
            req[idx]=all++;
        }
    }
    return cnt;
}

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

int countReplacement(int N, int inputSeq[])
{
    n=N;
    for(int i=0;i<n;i++)
        a[i]=inputSeq[i];
    if(check()==0)return 0;
    needed();
    vector<long long> v;
    long long maxx=n+1;
    for(int i=0;i<n;i++)
    {
        maxx=min(maxx,a[i]);
        if(a[i]!=req[i])v.push_back(i);
    }
    sort(v.begin(),v.end(),cmp);

    long long ans=1;
    long long last=n;
    for(int i=0;i<v.size();i++)
    {
        long long pos=v.size()-i;
        long long cnt=a[v[i]]-last-1;
        //cout<<v[i]<<" "<<pos<<" "<<cnt<<endl;
        ans=(ans*mult(pos,cnt))%mod;
        last=a[v[i]];
    }

    if(maxx>n)
    {
        for(int i=1;i<=n;i++)
        {
            ans=(ans*i)%mod;
        }
    }


    return (int)ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:118:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:151:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
# 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 456 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 3464 KB Output is correct
7 Correct 6 ms 1884 KB Output is correct
8 Correct 22 ms 6052 KB Output is correct
9 Correct 7 ms 2140 KB Output is correct
10 Correct 28 ms 6888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 13 ms 3420 KB Output is correct
7 Correct 8 ms 1972 KB Output is correct
8 Correct 27 ms 6116 KB Output is correct
9 Correct 7 ms 2068 KB Output is correct
10 Correct 26 ms 6980 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 444 KB Output is correct
13 Correct 16 ms 3156 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 38 ms 7316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 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
# 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 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 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 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 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 8 ms 2124 KB Output is correct
12 Correct 9 ms 2140 KB Output is correct
13 Correct 10 ms 2020 KB Output is correct
14 Correct 5 ms 1884 KB Output is correct
15 Correct 14 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 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 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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
6 Correct 0 ms 444 KB Output is correct
7 Incorrect 1 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -