Submission #852310

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

using namespace std;

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

map<int,int> m;

int valid(int n, int a[])
{
    for(int i=0;i<n;i++)
    {
        if(m[a[i]]!=0) return 0;
        m[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;
}

vector<int> v2;

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

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

    sort(v2.begin(), v2.end());
    long long ans=1;
    for(int i=1;i<v2.size();i++)
    {
        ans=ans*fastPow(v2.size()-i, v2[i].first-v2[i-1].first)%MOD;
    }

    if(mn>n) ans=ans*n%MOD;

    return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:122:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |     for(int i=1;i<v2.size();i++)
      |                 ~^~~~~~~~~~
gondola.cpp:124:44: error: request for member 'first' in 'v2.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
  124 |         ans=ans*fastPow(v2.size()-i, v2[i].first-v2[i-1].first)%MOD;
      |                                            ^~~~~
gondola.cpp:124:58: error: request for member 'first' in 'v2.std::vector<int>::operator[](((std::vector<int>::size_type)(i - 1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
  124 |         ans=ans*fastPow(v2.size()-i, v2[i].first-v2[i-1].first)%MOD;
      |                                                          ^~~~~
gondola.cpp:127:8: error: 'mn' was not declared in this scope; did you mean 'n'?
  127 |     if(mn>n) ans=ans*n%MOD;
      |        ^~
      |        n