Submission #852295

# Submission time Handle Problem Language Result Execution time Memory
852295 2023-09-21T14:39:58 Z DobromirAngelov Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include "gondola.h"
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int MAXN=1e5+5;
const int MAXVAL=250005;
const int MOD=1e9+9;

bool used[MAXN];

int valid(int n, int a[])
{
    for(int i=0;i<n;i++)
    {
        if(used[a[i]]) return 0;
        used[a[i]]=1;
    }

    int mn=1e9, idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<mn)
        {
            mn=a[i];
            idx=i;
        }
    }
    if(mn<=n)
    {
        int cur=mn+1;
        for(int i=idx+1;i!=idx;i++)
        {
            if(i>=n) i-=n;
            if(a[i]<=n && a[i]!=cur) return 0;
            cur++;
            if(i==n-1) i=-1;
        }
    }

    return 1;
}

int b[MAXN];
vector<pair<int,int> > v;

int replacement(int n, int a[], int replacementSeq[])
{
    int mn=1e9,idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<mn)
        {
            mn=a[i];
            idx=i;
        }
    }

    if(mn>n)
    {
        for(int i=0;i<n;i++) b[i]=i+1;
    }
    else
    {
        int cur=mn;
        b[idx]=cur++;
        for(int i=idx+1;i!=idx;i++)
        {
            if(i>=n) i-=n;
            if(cur>n) cur-=n;
            b[i]=cur++;
            if(i==n-1) i=-1;
        }
    }

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

    sort(v.begin(), v.end());
    int ptr=0;
    int cur=n;
    for(int i=0;i<v.size();i++)
    {
        replacementSeq[ptr++]=v[i].second;
        cur++;
        while(cur<v[i].first)
        {
            replacementSeq[ptr++]=cur++;
        }
    }

    return ptr;
}

int fastPow(int a,int pw)
{
    long long ret=1;
    while(pw>0)
    {
        if(pw&1) ret=ret*a%MOD;
        a=(long long) a*a%MOD;
        pw/=2;
    }
    return ret;
}

int countReplacement(int n, int a[])
{
    if(!valid(n,a)) return 0;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,a[i]);
    }
    if(mx==n) return 1;

    int mn=1e9,idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<mn)
        {
            mn=a[i];
            idx=i;
        }
    }

    if(mn>n)
    {
        for(int i=0;i<n;i++) b[i]=i+1;
    }
    else
    {
        int cur=mn;
        b[idx]=cur++;
        for(int i=idx+1;i!=idx;i++)
        {
            if(i>=n) i-=n;
            if(cur>n) cur-=n;
            b[i]=cur++;
            if(i==n-1) i=-1;
        }
    }

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

    sort(v.begin(), v.end());
    int ptr=0;
    int last=0;
    int cur=n;
    long long ans=1;
    for(int i=0;i<v.size();i++)
    {
        ptr++;
        cur++;
        while(cur<v[i].first)
        {
            ptr++; cur++;
        }
        ans=ans*fastPow(v.size()-i, ptr-last-1)%MOD;
        last=ptr;
    }

    if(mn>n)
    {
        for(int i=2;i<=n;i++) ans=ans*i%MOD;
    }

    return ans;
}

Compilation message

gondola.cpp: In function 'long long int replacement(long long int, long long int*, long long int*)':
gondola.cpp:85:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'long long int countReplacement(long long int, long long int*)':
gondola.cpp:157:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
/usr/bin/ld: /tmp/cc8cHQRr.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status